Repository navigation
Browser mode: coverage-v8 leaks memory between tests #11447
Description
Describe the bug
AI disclaimer: the reproduction was done using Claude, but the problem was very much confirmed by our CI/my laptop regularly running out of memory during full test suite runs
Might be related to #10810, but it's not the exact same symptom, so I wanted to report it either way.
In browser mode with coverage.provider: 'v8', the JS realm of every finished test file stays alive until the tab is closed. Each file adds its entire object graph (modules, DOM, closures) to the tab's heap, so a tab that runs many files eventually runs out of memory. In our suite (83 files, 12 tabs) tabs reached the --max-old-space-size cap and the run failed with [birpc] rpc is closed, cannot call "createTesters" / Browser connection was closed … Was the page closed unexpectedly?. Raising the heap size only delays the crash.
The leak doesn't happen without coverage, or with @vitest/coverage-istanbul.
You can find more info in the reproduction repo.
Reproduction
https://github.com/SomaH123/vitest-v8-coverage-leak-repro
The linked repo runs 8 tiny test files in one tab (fileParallelism: false, isolate: true). Each keeps a ~10 MB object graph on its own globalThis. A browser command forces a GC through CDP at the start of each file and prints the heap size and the number of live documents:
no coverage 5 MB/2 5 MB/2 5 MB/2 5 MB/2 5 MB/2 5 MB/2 5 MB/2 5 MB/2
coverage-v8 5 MB/2 13 MB/3 22 MB/4 31 MB/5 40 MB/6 49 MB/7 57 MB/8 66 MB/9
coverage-istanbul 5 MB/2 5 MB/2 5 MB/2 5 MB/2 5 MB/2 5 MB/2 5 MB/2 5 MB/2
(heap in MB / live documents)
With V8 coverage each finished file leaves one document and its heap behind. Without it, the removed iframe is collected.
System Info
System:
OS: Linux 6.18 Manjaro Linux
CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11850H @ 2.50GHz
Memory: 11.47 GB / 31.07 GB
Container: Yes
Shell: 5.3.9 - /bin/bash
Binaries:
Node: 24.19.0 - /home/somah/.nvm/versions/node/v24.19.0/bin/node
npm: 12.0.2 - /home/somah/.nvm/versions/node/v24.19.0/bin/npm
pnpm: 10.33.0 - /usr/bin/pnpm
Browsers:
Brave Browser: 147.1.89.145
Chromium: 148.0.7778.96
Firefox: 150.0.1
Firefox Developer Edition: 150.0.1
npmPackages:
@vitest/browser-playwright: 5.0.1 => 5.0.1
@vitest/coverage-istanbul: 5.0.1 => 5.0.1
@vitest/coverage-v8: 5.0.1 => 5.0.1
playwright: 1.63.0 => 1.63.0
vitest: 5.0.1 => 5.0.1Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Activity
[-]coverage-v8 leaks memory between tests[/-][+]Browser mode: coverage-v8 leaks memory between tests[/+]AriPerkkio commentedon Oct 2, 2026
Likely caused by
vitest/packages/coverage-v8/src/browser.ts
Lines 26 to 28 in 964e1a4
I think there was something going on when trying to disable precise coverage between browser mode test files. Need to re-check what that issue was.