From b4e665ef3cd4b441ec391096c3bc72d0aafd8e43 Mon Sep 17 00:00:00 2001 From: "arrz.dev" <55147716+arrzdev@users.noreply.github.com> Date: Tue, 17 Nov 2026 05:46:23 +0000 Subject: [PATCH] test(e2e): the reload storm names a crash of webkit's network process instead of reading it as lost tasks Playwright's WebKit contexts keep IndexedDB in the network process's memory. When the Linux build's network process aborts on heap corruption during the reload storm, the next document reads an empty store and the spec failed with "0 pending", the symptom of lost writes. The count checks now say when the network process crashed during the test. --- playground/e2e/stress-tasks.spec.ts | 15 ++++++- playground/e2e/support/browser-crash.ts | 60 +++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 playground/e2e/support/browser-crash.ts diff --git a/playground/e2e/stress-tasks.spec.ts b/playground/e2e/stress-tasks.spec.ts index 5fe74d7a..bd57dc54 100644 --- a/playground/e2e/stress-tasks.spec.ts +++ b/playground/e2e/stress-tasks.spec.ts @@ -1,5 +1,6 @@ import type { Page } from "@playwright/test" import { expect, test } from "@playwright/test" +import { watchNetworkProcess } from "./support/browser-crash" import { awaitClientHandover } from "./support/hydrated" import { card, @@ -29,6 +30,9 @@ import { * for the wrong reason. The reload storm counts errors only from the document * it settles on: WebKit reports the module imports a reload aborts in the * document it tore down as page errors, and those are the reload, not the app. + * Its count checks name a crash of WebKit's network process when there was one + * (`support/browser-crash.ts`): that empties the test context's storage and + * reads "0 pending" exactly like lost writes. */ const MUTATIONS = "/src/data/collections/todos/mutations.ts" @@ -127,20 +131,27 @@ test.describe("The tasks app under load", () => { await openApp(page) await createMany(page, "Kept", 50) await expect(taskCounts(page)).toHaveText(/50 pending/) + const network = watchNetworkProcess(page) //five reloads back to back, each tearing down a document still booting for (let reload = 0; reload < 5; reload += 1) { await page.reload() } await awaitClientHandover(page) - await expect(taskCounts(page)).toHaveText(/50 pending/) + await expect( + taskCounts(page), + network.explain("the storm lost tasks"), + ).toHaveText(/50 pending/) expect(await storedRows(page)).toHaveLength(50) //and the document that follows the storm boots clean, start to finish const errors = collectErrors(page) await page.reload() await awaitClientHandover(page) - await expect(taskCounts(page)).toHaveText(/50 pending/) + await expect( + taskCounts(page), + network.explain("the reload after the storm lost tasks"), + ).toHaveText(/50 pending/) expect(await storedRows(page)).toHaveLength(50) expect(errors).toEqual([]) }) diff --git a/playground/e2e/support/browser-crash.ts b/playground/e2e/support/browser-crash.ts new file mode 100644 index 00000000..6a01bfe7 --- /dev/null +++ b/playground/e2e/support/browser-crash.ts @@ -0,0 +1,60 @@ +import type { Page } from "@playwright/test" + +/* + * A crash of WebKit's network process, told apart from the app losing data. + * + * Playwright's WebKit contexts are ephemeral: IndexedDB, localStorage and the + * cookie jar live in the memory of the network process, not on disk. When that + * process dies the browser starts a new one with empty storage, so the next + * document reads an empty store and the tasks app shows "0 pending" — the + * symptom of lost writes, though every write had committed. + * + * The Linux WebKit build does crash that way under a reload storm on a loaded + * machine: each reload cancels a hundred dev-server module requests, a child + * process logs a GLib refcount assertion and then glibc's "corrupted + * double-linked list", and the browser's stderr says "WebKit encountered an + * internal error. This is a WebKit bug." Safari's network stack is not GLib, + * and Safari keeps IndexedDB on disk; this is the test browser, not something + * the app can guard against. + * + * The page sees the crash in two ways: each load in flight fails with "WebKit + * encountered an internal error", and an open WebSocket (the dev server's HMR + * socket) reports "Network process crashed". Either one is enough. + */ + +const CRASH_SIGNS = [ + /WebKit encountered an internal error/, + /Network process crashed/, +] + +export type NetworkProcessWatch = { + /** The first sign of a crash seen so far, or null. */ + crash: () => string | null + /** An assertion message: `what`, plus the crash when there was one. */ + explain: (what: string) => string +} + +/** Watch `page` for the signs that WebKit's network process crashed. */ +export function watchNetworkProcess(page: Page): NetworkProcessWatch { + let first: string | null = null + const note = (text: string) => { + if (first === null && CRASH_SIGNS.some((sign) => sign.test(text))) { + first = text + } + } + page.on("requestfailed", (request) => + note(`${request.failure()?.errorText ?? ""} (${request.url()})`), + ) + page.on("console", (message) => { + if (message.type() === "error") note(message.text()) + }) + return { + crash: () => first, + explain: (what) => + first === null + ? what + : `${what} — but WebKit's network process crashed during the test ` + + `(${first}), which empties an ephemeral context's storage: read this ` + + "as a browser crash, not as the app losing writes", + } +}