vmThreads: teardown timeout only logs and a stuck worker is never force-terminated, so the process can hang
Describe the bug
With the vmThreads pool, a full run logs teardown timeouts for arbitrary workers, and under memory pressure it can stop exiting altogether: the vitest process stays alive (observed reparented to PID 1, ~140% CPU, ~4 GiB RSS, 13+ min) and SIGTERM does not stop it — only SIGKILL does. While it lived, a new single-file vitest run did not finish in 10 minutes.
[vitest-pool]: Timeout terminating vmThreads worker for test files <path>.spec.ts.Bisect says it is not a specific test file. Across four full runs of the same 214-file suite it logged 1, 3, 7 and 8 timeouts, all naming different files; each named file passes alone, and each half of the suite (100 and 113 files, same worker count) logs zero. The full suite reproduces consistently with vmThreads, while pool=forks (2 runs, one under heavy load) and vmThreads --maxWorkers=4 log zero on the same machine. It scales with the number of concurrent worker stops and machine contention.
| Run | Wall | Teardown timeouts | Files named (sample) |
|---|---|---|---|
vmThreads default (load ~20) |
11m28s | 1 | src/mocks/onoff-content-campaigns.acl-alignment.spec.ts |
vmThreads default (load ~4) |
219s | 3 | scripts/finding-refs.spec.ts, src/models/collection.model.spec.ts, src/utils/week-slug.utils.spec.ts |
vmThreads default (load ~20) |
623s | 7 | src/testing/test-environment.spec.ts, src/app/pipes/repeat.pipe.spec.ts, … |
vmThreads --maxWorkers=8 (load ~20) |
972s | 8 | e2e/_utils/collection-fixtures.spec.ts, src/testing/sitemap-xml.spec.ts, … |
vmThreads --maxWorkers=4 |
163s | 0 | — |
pool=forks (2 runs) |
164s / 182s | 0 / 0 | — |
vmThreads halves (src/app / rest) |
68s / 78s | 0 / 0 | — |
In Vitest 4.1.11 (dist/chunks/cli-api.*.js) and 5.0.0 (dist/chunks/index.*.js) the branch is identical:
if (!runner.isTerminated) {
const id = setTimeout(() => this.logger.error(
`[vitest-pool]: Timeout terminating ${task.worker} worker for test files ${formatFiles(task)}.`
), this.options.teardownTimeout); // default 10_000 ms
this.exitPromises.push(
runner.stop({ force: resolver.isRejected }) // graceful stop for a non-rejected task
.then(() => clearTimeout(id))
.catch(...)
);
}The timeout only logs. For a task that finished successfully force is false, so a worker that does not answer in time is never force-terminated, and since exitPromises is awaited before exiting, a stop that never settles keeps the process — and its heap — alive.
Reproduction
No minimal reproduction of the hang yet; the timeout lines reproduce reliably with a large suite. Recipe:
@analogjs/vite-plugin-angular2.7.1 (it setspool: 'vmThreads'unless the config declares one)- 214 spec files (Angular 22 + happy-dom),
vitest rununder CPU/memory contention grep 'Timeout terminating'on the output
Named files are arbitrary and change per run (scripts/finding-refs.spec.ts, src/models/collection.model.spec.ts, src/utils/week-slug.utils.spec.ts, src/testing/test-environment.spec.ts, src/app/pipes/repeat.pipe.spec.ts, …). --pool=forks and --maxWorkers=4 log none.
I can try to reduce it to a shareable repository if that helps triage.
Suggested direction
Once teardownTimeout elapses, force-terminate the runner (or reject its stop promise) so the run cannot stay alive; keep the log as the signal.
Related
- #8766 (closed) — same family on the
forkspool; the maintainer attributed it to tests leaving pending async work, but the timeout path above is unchanged in 5.0.0. - #8649 (closed) —
Closing rpc while "fetch" was pendingon the v4 pool rewrite. - #10743 — per-file isolation in vm pools with
maxWorkers: 1(v5); #10543 and #9140 — worker termination fixes; #11363 — configurable worker start timeout. - Docs:
isolate"has no effect onvmThreadsandvmForkspools".
System Info
Binaries:
Node: 24.18.0
npmPackages:
@analogjs/vite-plugin-angular: 2.7.1
vite: 8.2.2
vitest: 4.1.11Validations
- 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.
- The provided reproduction is a minimal reproducible example of the bug. (not yet — recipe above)
Source: vitest-dev/vitest