-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Labels
Description
Describe the bug
There is a race condition in the new worker pool implementation.
Reproduction
See repro.zip.
The relevant part is the run-vitest.ts file.
import { createVitest } from "vitest/node";
const vitest = await createVitest("test", {
pool: "threads",
coverage: { enabled: false },
maxWorkers: 1,
maxConcurrency: 1,
watch: false,
bail: 1,
reporters: [],
});
while (vitest.state.errorsSet.size === 0) {
await vitest.start();
}
reportErrors();
function reportErrors() {
if (vitest.state.errorsSet.size > 0) {
const msg = [...vitest.state.errorsSet]
.map((err) => err.message)
.join("\n");
console.error("Test run errored with:\n", msg);
} else {
console.log("No errors!");
}
}I would expect this program to run infinitely. What actually happens:
- It stops after ~1 second
- It logs:
[vitest-pool]: Cannot run tasks while pool is cancelling
The race condition concerns bail. The canceling of the run doesn't finish before the run itself finishes (there is 1 failing test).
System Info
System:
OS: macOS 26.0.1
CPU: (14) arm64 Apple M4 Pro
Memory: 989.08 MB / 48.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.18.0 - /Users/nicojs/.nvm/versions/node/v22.18.0/bin/node
Yarn: 1.22.22 - /Users/nicojs/.nvm/versions/node/v22.18.0/bin/yarn
npm: 11.5.2 - /Users/nicojs/.nvm/versions/node/v22.18.0/bin/npm
pnpm: 10.19.0 - /Users/nicojs/Library/pnpm/pnpm
Browsers:
Chrome: 141.0.7390.123
Edge: 141.0.3537.99
Firefox: 144.0
Safari: 26.0.1
npmPackages:
vitest: ^4.0.4 => 4.0.4Used 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.
Reactions are currently unavailable