Repository navigation
Description
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/browsersetupClient), soorchestrator.createTesters([file])in the pool'srunNextTestcan wait forever. Pending calls are only rejected by the websocketclosehandler ("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 postsresponse:executeon the BroadcastChannel — no timeout, and only aniframeerrorevent can reject it. testTimeoutandretryare 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):
- A mid-run dep re-optimization ("new dependencies optimized … optimized dependencies changed. reloading"): the vite full-reload destroys every tester iframe's JS context mid-file. The "Vite unexpectedly reloaded a test" warning ("Vite unexpectedly reloaded a test" warning whilst running Vitest #7333, Tests fail: "Vite unexpectedly reloaded a test. This may cause tests to fail" #8447) prints, then the run makes no further progress.
- Disk exhaustion during the run (see Browser mode: Chromium disk usage accumulates per test file, exhausting disk on long runs #9437): the vite server can no longer serve modules, the executing tester never completes, socket stays open.
- On CI (GitHub Actions, ubuntu-latest) we saw the suite go from steady per-file output to total silence mid-run, then sit for 18 minutes until
timeout-minutes: 20cancelled the job.
Reproduction
Deterministic illustration of the missing deadline (any browser-mode project, playwright provider):
vitest runa suite with enough files to take ~30s.- Mid-run, freeze the browser:
pkill -STOP -f headless_shell(the websocket stays open, so the close-handler rescue never fires). - The run produces no further output and never times out —
testTimeoutcannot 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
github-actions commentedon Jul 17, 2026
Hello @joelfillmore. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with
needs reproductionwill be closed if they have no activity within 3 days.guillem-aistech commentedon Jul 20, 2026
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
vitest@4.1.9andvitest@5.0.0-beta.6Symptom
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: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 runs5.0.0-beta.6: 2 of 5 full runsBoth samples are small; I would not read the difference as an improvement.
On the
[birpc] rpc is closedstackOf 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:
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.
joelfillmore commentedon Jul 21, 2026
Apologies, somehow I missed the request for a repro.
Here is a minimal reproduction: https://github.com/joelfillmore/vitest-browser-hang-repro
repro:freezedemonstrates 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:reloadshows 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 untiltimeout-minutescancelled 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
executeand then dies mid-file still hangs — the response wait is unbounded and the node-sidecreateTestersRPC usestimeout: -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!
joelfillmore commentedon Jul 21, 2026
@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!
joelfillmore commentedon Jul 22, 2026
@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!
FyrBridd commentedon Aug 3, 2026
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
preparehandshake rather thanexecute.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: trueevery 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 viaPage.getFrameTreeon a wedged run). So it is not just "tester died mid-file" — the tester never starts, and it isprepareIframethat hangs, one step earlier than theexecutepath in your write-up:iframe.onerrorcannot rescue this. A failed iframe navigation firesload, noterror. Verified directly against the same Chromium build:So the
onerrorbranch is dead for exactly the failure it looks like it should catch, andsendEventToIframethen waits forever on aresponse:preparethat an error document will never post.Confirming your reading of the node side on
@vitest/browser3.2.6:setupClientstill creates the birpc withtimeout: -1, and the orchestrator's own websocket stays open throughout, so thews.on("close")rescue never fires. Browser-side debug output (VITEST_BROWSER_DEBUG) ends oncreate iframe <file>and nothing follows. The node process and the Vite dev server stay perfectly healthy —curlof 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:
Failed to fetch dynamically imported moduleas an ordinary test failureBrowser connection was closed while running testsWorkaround, 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
createTesterswould cover this too. One cheaper partial: inprepareIframe'sonload, check that the frame actually committed the expected tester document before starting the handshake (iframe.contentWindow.location.hrefmismatches the expectedsrcfor an error page, and may throwSecurityErroroutright), 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:
fix(test): run the session-killing browser suite last (#389)
feat(tool-cards): render the element page/extension tools acted on (#348
fix(test): pre-warm vite dep optimization for browser suites so mid-r…
fix(test): pre-warm vite dep optimization for browser suites so mid-r…
alfupe commentedon Aug 14, 2026
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 branchfeat/xto.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.
CI: mitigate a known, unpatched Vitest browser-mode hang (vitest-dev/…
CI: widen diagnostics to Vitest's own orchestration layer
Migrate visual regression suite from Vitest browser mode to Playwrigh…
CI: mitigate a known, unpatched Vitest browser-mode hang (vitest-dev/…
CI: widen diagnostics to Vitest's own orchestration layer
Migrate visual regression suite from Vitest browser mode to Playwrigh…
CI: mitigate a known, unpatched Vitest browser-mode hang (vitest-dev/…
CI: widen diagnostics to Vitest's own orchestration layer
EXPERIMENT: upgrade to vitest/browser-playwright/coverage-v8 5.0.0-rc.2
fix: mount view panels in the .output-panel/.is-active shell after re…