Browser mode hangs for ever when a test iframe never fires `load`
Describe the bug
In browser mode, a run can hang for ever with no output and no CPU use. It happens when one test file's iframe never fires load: BrowserOrchestrator.prepareIframe awaits a promise that only iframe.onload and iframe.onerror can settle, and neither is bounded by a timer.
// @vitest/browser/dist/client/__vitest_browser__/orchestrator-*.js
async prepareIframe(container, iframeId, startTime, otelContext) {
const iframe = this.createTestIframe(iframeId);
container.appendChild(iframe);
await new Promise((resolve, reject) => {
iframe.onload = () => { /* ... waitForReady(), which *is* bounded ... */ };
iframe.onerror = (e) => { /* ... */ };
});
return iframe;
}waitForReady has getIframeTimeout(), and sendEventToIframe has one for the ack: message, but the load itself has none: if the browser never fires either event, the orchestrator waits for ever, the pool waits for that session for ever, and the run never ends.
There is a second unbounded wait in sendEventToIframe: once ack:<event> arrives, ackTimer is cleared and nothing bounds response:<event>. A tester that stops after acknowledging (it awaits client.waitForConnection() right after posting the ack) hangs the run the same way.
What we see
WebKit (Playwright) on macOS, under CPU pressure. One file out of 128 never reports; which file varies between runs. DEBUG='vitest:browser:*' VITEST_BROWSER_DEBUG=true shows the pool handing the file to a session and nothing from that session afterwards — no iframe loaded with href, no iframe events, no tester connection:
19:21:27.644 vitest:browser:pool [d30da4d6…] run test { filepath: '…/shell.browser.test.ts' }
(nothing more from d30da4d6 for the next five minutes, until the run was killed)Other sessions in the same browser keep finishing files. Every process is idle; nothing crashes. On our CI (3-core macOS runner) the same thing held a job for over three hours until we cancelled it; the job has no other symptom.
Reproduction
We have not managed a small reproduction — it needs a starved machine, and it is intermittent. On an 8-core Mac with six busy loops running (perl -e '1 while 1'), a 128-file suite (three browser projects, Chromium and WebKit, ~40 pages) hung on the first run; six later runs under the same load passed. Three runs without the extra load passed. On CI (3 cores, ~12 pages) it has hung twice in a day's worth of runs, and a Chromium test in the same job has timed out where it normally takes milliseconds.
The same wait, reached another way
#10520 and #10860 are the same unbounded wait with a different trigger: a + in a path leaves the tester ignoring every event, "the orchestrator's prepare promise never resolves". Whatever keeps load or the tester quiet — a mismatched id, a starved browser — the run has no way to end. A bound on the wait would turn all of these into a message about one file instead of a run that never returns.
Suggestion
Bound the load the way waitForReady is bounded, and bound the response after the ack. Locally we patch the built client:
- reject after
getIframeTimeout()if neitherloadnorerrorfires, - after
ack:, reject ifresponse:has not arrived withingetIframeTimeout() * 10.
Both turn a permanent hang into a normal failure for one file, and the rest of the suite still runs. Happy to open a PR if the approach looks right.
Versions
vitest 5.0.0, @vitest/browser 5.0.0, @vitest/browser-playwright 5.0.0, playwright 1.63.0, macOS 15 (arm64), node 24.
Source: vitest-dev/vitest