Repository navigation
Description
Version
v24.22.3 (also v24.11.0, v24.14.0, v24.18.1, v24.19.0, v24.21.0 and v26.13.1)
Platform
Darwin 27.2.0 arm64 (macOS 27.2.1)
Subsystem
worker_threads
What steps will reproduce the bug?
// repro.js
const { Worker } = require('node:worker_threads');
const workerCode = `
const { parentPort } = require('node:worker_threads');
parentPort.on('message', async (code) => { await null; eval(code); });
parentPort.postMessage('ready');
`;
(async () => {
for (let i = 1; i <= 200; i++) {
const worker = new Worker(workerCode, { eval: true });
await new Promise((resolve) => worker.once('message', resolve));
const exited = new Promise((resolve) => worker.once('exit', () => resolve(true)));
worker.postMessage('while(true);');
worker.terminate();
const ok = await Promise.race([exited, new Promise((resolve) => setTimeout(() => resolve(false), 1000))]);
if (!ok) {
console.log(`worker ${worker.threadId} still running after terminate() (iteration ${i})`);
process.exit(1);
}
}
console.log('every worker exited');
})();node --enable-source-maps repro.js
How often does it reproduce? Is there a required condition?
Often on the first or second iteration, sometimes not for a few dozen - it's a race. It needs --enable-source-maps: without the flag I haven't seen it happen at all on any version. I couldn't reproduce it on v20.15.1 or v22.11.0, with or without the flag.
It also seems to need terminate() to land right as the worker starts the task. If I wait 50 ms or 500 ms after postMessage() before calling terminate(), every worker exits. An idle task (eg. a long setTimeout) instead of a busy loop exits fine too.
What is the expected behavior? Why is that the expected behavior?
terminate() stops the worker and it emits 'exit', same as without --enable-source-maps.
What do you see instead?
The worker never exits and keeps a CPU core busy until the process is killed. terminate() returns as usual, so the caller thinks it's gone.
A sample of the stuck process shows the worker thread still running the task's JS from a microtask checkpoint:
node::worker::Worker::Run()
node::SpinEventLoopInternal
uv_run -> uv__io_poll -> uv__async_io
node::worker::MessagePort::OnMessage
node::InternalCallbackScope::Close()
v8::internal::MicrotaskQueue::PerformCheckpoint
v8::internal::MicrotaskQueue::RunMicrotasks
Builtins_PromiseFulfillReactionJob
Builtins_AsyncFunctionAwaitResolveClosure
(JIT code)
Additional information
I found this through piscina (a worker pool), where aborting a running task calls worker.terminate(). Its test suite runs with --enable-source-maps and one test aborts a while(true); task, so the test process occasionally never exits. Any app that runs with source maps on and cancels CPU-bound worker tasks can end up with a thread spinning in the background.
Possibly related: #66439 also involves a termination interrupting a microtask checkpoint, though the symptom there is different.
Activity
legendecas commentedon Nov 23, 2026
I think this is a V8 issue. Fixing in https://chromium-review.googlesource.com/c/v8/v8/+/8855220.