fix(ext/node): process.exit() in worker immediately halts execution#32169
Merged
bartlomieju merged 4 commits intodenoland:mainfrom Feb 15, 2026
Merged
fix(ext/node): process.exit() in worker immediately halts execution#32169bartlomieju merged 4 commits intodenoland:mainfrom
bartlomieju merged 4 commits intodenoland:mainfrom
Conversation
In Node.js, process.exit() inside a worker immediately stops all JS execution at the C++ level. In Deno, it called workerClose() which triggered V8's terminate_execution(), but JS continued running because V8 only checks the termination flag at function entries and loop back-edges, not during function returns. Fix by adding an infinite loop after process.reallyExit() that gives V8 a loop back-edge to detect the pending termination and throw an uncatchable TerminationException. On the main thread the loop is unreachable since reallyExit() calls std::process::exit(). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
4cc2b5e to
d29164f
Compare
Member
Author
|
The fix seems a bit bizarre, but does work |
littledivy
reviewed
Feb 15, 2026
Comment on lines
+132
to
+142
| // In a worker, reallyExit() returns because Deno.exit() calls workerClose() | ||
| // instead of std::process::exit(). But workerClose() already called V8's | ||
| // terminate_execution(). Spinning here gives V8 a loop back-edge to detect | ||
| // the pending termination and throw an uncatchable TerminationException, | ||
| // matching Node.js behavior where process.exit() immediately halts all JS. | ||
| // On the main thread reallyExit() normally never returns, but users can | ||
| // override it (test-process-really-exit.js), so only spin in workers. | ||
| if (internals.__isWorkerThread) { | ||
| // deno-lint-ignore no-empty | ||
| for (;;) {} | ||
| } |
Member
There was a problem hiding this comment.
I assume there is a stack guard in V8 for this so just a function call should be enough to trigger this
Member
There was a problem hiding this comment.
Member
Author
There was a problem hiding this comment.
I tried that with Claude I got this:
The tests fail — nop() alone isn't sufficient. The issue is that in Deno, process.reallyExit is a JS function (not a C++ binding like in Node.js), so V8's
stack guard spoofing from terminate_execution() may not persist through the multiple JS return frames between the op and the nop() call. The for (;;) {}
loop is needed because it provides a loop back-edge where V8 reliably checks for termination.
littledivy
approved these changes
Feb 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In Node.js,
process.exit()inside a worker immediately stops all JS execution at the C++ level. In Deno, it calledworkerClose()which triggered V8'sterminate_execution(), but JS continued running because V8 only checks the termination flag at function entries and loop back-edges — not during function returns.Adds an infinite loop after
process.reallyExit()that gives V8 a loop back-edge to detect the pending termination and throw an uncatchableTerminationException. On the main thread the loop is unreachable sincereallyExit()callsstd::process::exit().Enables 2 new node_compat tests:
test-worker-voluntarily-exit-followed-by-addition.jstest-worker-voluntarily-exit-followed-by-throw.jsTest plan
cargo test --test node_compat parallel -- --filter "test-worker-voluntarily-exit"— both passcargo test --test node_compat parallel -- --filter "test-worker-terminate"— no regressionscargo test --test node_compat parallel -- --filter "test-worker-exit"— no regressions🤖 Generated with Claude Code