Skip to content

Browser mode: run hangs forever when a tester page dies without closing its websocket (no run-level deadline on createTesters) #10791

Closed

Description

@joelfillmore

Describe the bug

In browser mode, if a tester page's JS context dies without closing its websocket, the whole run hangs forever with no output — testTimeout, retry, and reporters all go silent until something external kills the process (locally Ctrl-C, on CI timeout-minutes).

The hang is structural — there is no run-level deadline anywhere on the per-file execution path:

  • The node-side RPC to the orchestrator is created with timeout: -1 (@vitest/browser setupClient), so orchestrator.createTesters([file]) in the pool's runNextTest can wait forever. Pending calls are only rejected by the websocket close handler ("Browser connection was closed while running tests").
  • In the page, the orchestrator's sendEventToIframe({ event: 'execute' }) returns a promise that resolves only when the tester posts response:execute on the BroadcastChannel — no timeout, and only an iframeerror event can reject it.
  • testTimeout and retry are enforced inside the tester iframe's own JS, so once that context is gone they can never fire.

browser.connectTimeout only covers session creation; nothing covers "tester died mid-file with the socket still open."

Real triggers we hit (all funnel into the same unbounded wait):

Reproduction

Deterministic illustration of the missing deadline (any browser-mode project, playwright provider):

  1. vitest run a suite with enough files to take ~30s.
  2. Mid-run, freeze the browser: pkill -STOP -f headless_shell (the websocket stays open, so the close-handler rescue never fires).
  3. The run produces no further output and never times out — testTimeout cannot fire because it lives inside the frozen page.

The organic version (optimizer-reload trigger) is racy by nature: cold optimizer cache + a dep that misses the initial scan → mid-run re-optimize → full reload → hang. Observed repeatedly on a ~110-file / ~850-test storybook (@storybook/addon-vitest) suite.

Expected behavior

A tester that stops responding should fail that test file (and let the run continue or fail fast), not hang the run forever. Possible shapes: a configurable deadline around createTesters per file, or a heartbeat between orchestrator/tester and the node side that converts a dead-but-connected session into a file-level error.

Related: #9509 (load-time flakes), #10520 (hang at collection), #8447 / #7333 (unexpected reload warning), #9437 (disk accumulation — one of the triggers).

System Info

  • vitest / @vitest/browser / @vitest/browser-playwright 4.1.10 (also reproduced conceptually against current dist)
  • provider: playwright, chromium headless
  • observed on macOS 15 (arm64), ubuntu 24 (x64 GitHub runners, docker arm64)
  • node 24

Used Package Manager

pnpm

Activity

  1. github-actions commented on Jul 17, 2026

    @github-actions

    Hello @joelfillmore. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with needs reproduction will be closed if they have no activity within 3 days.

  2. guillem-aistech commented on Jul 20, 2026

    @guillem-aistech

    Independent corroboration from a different environment. No minimal reproduction, so treat this as a second data point rather than the repro you're asking for.

    Environment

    • Linux x64, 16 cores, Node v25.9.0, yarn
    • playwright 1.60.0, chromium-1223, headless
    • Observed on vitest@4.1.9 and vitest@5.0.0-beta.6

    Symptom

    On a full test run across several packages, one spec reports (0 test) — the file is picked up but registers none of its tests. A different file each time. Four distinct files so far, spanning both browser-mode and screenshot specs:

    • two component browser specs (4 and 21 tests)
    • two screenshot specs (18 and 9 tests)

    Each was re-run individually afterwards and passed fully (4/4, 21/21, 18/18, 9/9). Only the parallel full run reproduces it.

    Frequency

    • 4.1.9: 3 of 3 usable full runs
    • 5.0.0-beta.6: 2 of 5 full runs

    Both samples are small; I would not read the difference as an improvement.

    On the [birpc] rpc is closed stack

    Of the three occurrences on 4.1.9, two carried it and one did not. Neither occurrence on 5.0.0-beta.6 carried it. So the stack accompanies some but not all occurrences, on both versions — consistent with your point that the pending call is incidental and only surfaces if the socket close happens to reject one. When present it read:

    Caused by: Error: [birpc] rpc is closed, cannot call "resolveManualMock"
     ❯ Proxy.$close .../@vitest/browser/dist/index.js:2911
     ❯ WebSocket.emitClose .../ws/lib/websocket.js:279
    

    What did not stop it

    Serialising so that only one browser instance is alive at a time. It reduced frequency but still fired with serialisation active.

    Caveat

    Private repo, no minimal reproduction. I could not isolate whether the trigger is import-graph size, parallel spec count, or something else, and I did not test individual mitigations in isolation. Posting only because the "different file every run, passes alone" shape matches your description and confirms it is not specific to macOS/pnpm.

  3. joelfillmore commented on Jul 21, 2026

    @joelfillmore
    Author

    Apologies, somehow I missed the request for a repro.

    Here is a minimal reproduction: https://github.com/joelfillmore/vitest-browser-hang-repro

    pnpm install && pnpm exec playwright install chromium
    pnpm repro:freeze    # deterministic: freezes the tester mid-run (SIGSTOP, socket stays open)
    pnpm repro:reload    # organic trigger: mid-run dep discovery -> vite full-reload

    repro:freeze demonstrates the defect deterministically: a normal run (testTimeout: 10_000) is frozen mid-file with the websocket still open — no timeout ever fires and the run produces no further output until killed. The SIGSTOP is a stand-in for any silent tester death with the socket open (mid-run vite full-reload, wedged renderer, vite server unable to serve modules after disk exhaustion, #9437).

    repro:reload shows the real-world trigger on every cold-cache run: a dependency hidden behind a virtual module escapes the initial dep scan, so importing it mid-run re-optimizes and full-reloads every tester ("Vite unexpectedly reloaded a test", #7333 / #8447). On a fast machine vitest recovers from the reload; under load (more files, parallel sessions, constrained CI runners) it lands while testers are mid-prepare/execute/cleanup and becomes the permanent hang — we hit this repeatedly on GitHub Actions with a ~110-file suite (steady per-file output, then total silence until timeout-minutes cancelled the job after 18 minutes).

    Note on #10656 (post-4.1.10): the acknowledgement timeout bounds "tester was already dead when the message was sent", but a tester that acks execute and then dies mid-file still hangs — the response wait is unbounded and the node-side createTesters RPC uses timeout: -1.

    Let me know if you'd like me to submit a PR.

    Looking at this for a bit, the shape that seems to fit the existing design is extending the one-shot ack into a periodic liveness signal while work is in flight (emitted from a worker, so a legitimately sync-busy main thread does not false-positive), with the orchestrator rejecting the pending wait when the signal stops. However, not super familiar with vitest architecture so happy to defer to someone else if there is a better way to improve this.

    Thanks!

  4. joelfillmore commented on Jul 21, 2026

    @joelfillmore
    Author

    @sheremet-va - sorry I missed the request for a repro, but have added one in the comment above. Would it be possible to reopen? Thanks!

  5. joelfillmore commented on Jul 22, 2026

    @joelfillmore
    Author

    @sheremet-va - I think it was auto-closed again because it still has the "needs reproduction" tag.

    Let me know if the repro and description I linked to in my second comment is missing anything. Or whether you'd like me to submit a PR. Thanks!

  6. FyrBridd commented on Aug 3, 2026

    @FyrBridd

    Another concrete trigger for this, with the failing layer identified. Same shape as your optimizer-reload and disk-exhaustion cases — tester dies (or never lives) with the socket still open — but the cause is on the browser's side of the wire, and it also hits the prepare handshake rather than execute.

    Trigger: Chromium refuses new requests browser-wide. Late in a long run, Chromium starts failing every request to the Vite dev server with net::ERR_INSUFFICIENT_RESOURCES. All sessions fail within the same millisecond, in separate renderer processes, so it is a browser-scoped budget rather than a per-page or concurrency limit. In-flight request count is 0–17 at the moment of failure (peak across the run is ~70), so it is not concurrency — it is cumulative over requests issued during the browser's lifetime.

    What drives it here is request volume: with browser.isolate: true every test file gets a fresh iframe that re-requests the whole module graph. Measured on a 100-file storybook suite: 6,773 requests across 27 suites, but only 562 unique URLs — ~250 requests per file, ~92% repeats. A full run pushes ~25k requests through one browser process.

    Where it lands. When the refusal hits the tester iframe's own navigation, the frame commits chrome-error://chromewebdata/ (confirmed via Page.getFrameTree on a wedged run). So it is not just "tester died mid-file" — the tester never starts, and it is prepareIframe that hangs, one step earlier than the execute path in your write-up:

    // dist/client/__vitest_browser__/orchestrator-*.js
    iframe.onload = () => {
      this.iframes.set(iframeId, iframe);
      sendEventToIframe({ event: "prepare", iframeId, startTime })
        .then(resolve, reject);
    };
    iframe.onerror = (e) => { /* ... */ };

    iframe.onerror cannot rescue this. A failed iframe navigation fires load, not error. Verified directly against the same Chromium build:

    await page.route("**/doomed", (route) => route.abort("failed"));
    // iframe.onload -> pushes "load";  iframe.onerror -> never runs
    // events fired: ["load"]

    So the onerror branch is dead for exactly the failure it looks like it should catch, and sendEventToIframe then waits forever on a response:prepare that an error document will never post.

    Confirming your reading of the node side on @vitest/browser 3.2.6: setupClient still creates the birpc with timeout: -1, and the orchestrator's own websocket stays open throughout, so the ws.on("close") rescue never fires. Browser-side debug output (VITEST_BROWSER_DEBUG) ends on create iframe <file> and nothing follows. The node process and the Vite dev server stay perfectly healthy — curl of a module mid-wedge returned 200 in 1.3 ms.

    Same fault, three different symptoms depending on where the refusal lands, which may explain some reports that look unrelated:

    • during the tester iframe's navigation → the silent hang (this issue)
    • during a story's dynamic import → Failed to fetch dynamically imported module as an ordinary test failure
    • when it takes out a live tester page → Browser connection was closed while running tests

    Workaround, if it helps anyone landing here: shard the run so each browser process sees fewer files (--shard=1/4 … 4/4, each its own vitest process and therefore its own browser). On a machine where 10 of 10 unsharded runs hung, four shards pass the full 100 suites in 67 s. It buys linear margin, obviously — it does not remove the unbounded wait, which is why the deadline you propose still matters.

    On the fix shapes you suggest — a per-file deadline around createTesters would cover this too. One cheaper partial: in prepareIframe's onload, check that the frame actually committed the expected tester document before starting the handshake (iframe.contentWindow.location.href mismatches the expected src for an error page, and may throw SecurityError outright), and reject if not. That converts this particular class into a named per-file failure without needing a timer, though it would not cover a tester that dies after connecting.

    System info, since it is a different version line from yours:

    vitest / @vitest/browser 3.2.6
    provider: playwright 1.59.1, chromium headless (HeadlessChrome/149.0.7827.55)
    node 22, ubuntu (local) and ubuntu-latest GitHub runners
    package manager: npm
    
  7. alfupe commented on Aug 14, 2026

    @alfupe

    Data point on how painful the missing run-level deadline is in practice: on vitest@4.1.10 (current latest stable), a + anywhere in the project path still triggers #10520 — its fix (#10521) landed after the 4.1.x line and is only contained in the v5 pre-releases (verified in v5.0.0-beta.6+). The result is exactly the failure mode described here: RUN v4.1.10, browser launched, then silence forever — no error, no timeout, nothing to grep for.

    It is easy to hit without an exotic setup: tooling that derives directory names from branch names produces + paths (e.g. Claude Code's git worktrees map branch feat/x to .claude/worktrees/feat+x), and any browser-mode project tested inside one hangs silently. Confirmed with a clean A/B — same tree byte-for-byte, only the directory name differs.

    A run-level deadline like the one proposed here would have turned an undiagnosable hang into an actionable error pointing at the tester that never got ready.

  8. locked and limited conversation to collaborators on Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions