Skip to content

Browser mode: coverage-v8 leaks memory between tests #11447

Closed

Description

@SomaH123

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.1

Used Package Manager

npm

Validations

Activity

  1. added theissue type on Oct 2, 2026
  2. changed the title [-]coverage-v8 leaks memory between tests[/-] [+]Browser mode: coverage-v8 leaks memory between tests[/+] on Oct 2, 2026
  3. AriPerkkio commented on Oct 2, 2026

    @AriPerkkio
    Member

    Likely caused by

    stopCoverage() {
    // Browser mode should not stop coverage as same V8 instance is shared between tests
    },

    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.

  4. added
    feat: coverageIssues and PRs related to the coverage feature
    feat: browserIssues and PRs related to the browser runner
    and removed on Oct 2, 2026
  5. locked and limited conversation to collaborators on Oct 21, 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

    feat: browserIssues and PRs related to the browser runnerfeat: coverageIssues and PRs related to the coverage feature

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions