fix(ext/node): fix worker exit code propagation in worker_threads#32124
Merged
bartlomieju merged 2 commits intodenoland:mainfrom Feb 12, 2026
Merged
fix(ext/node): fix worker exit code propagation in worker_threads#32124bartlomieju merged 2 commits intodenoland:mainfrom
worker_threads#32124bartlomieju merged 2 commits intodenoland:mainfrom
Conversation
Properly propagate `process.exitCode` from Node worker threads to the
parent, matching Node.js behavior. Previously, worker exit codes were
hardcoded to 0 (natural exit) or 1 (error exit), ignoring
`process.exitCode` set by the worker.
- Add exit code field to `WorkerControlEvent::TerminalError` so parent
receives the actual exit code
- Dispatch `process.emit("exit")` on natural worker exit to run exit
handlers before sending the final exit code
- Implement `process._fatalException` for uncaught exception handling,
including exit code 6 when it's monkey-patched to not be a function
- Use `data.exitCode ?? 1` on parent side instead of hardcoded `1`
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
process.exitCodefrom Nodeworker_threadsto the parent, matching Node.js behavior. Previously exit codes were hardcoded to 0 (natural exit) or 1 (error exit), ignoringprocess.exitCodeset by the worker.WorkerControlEvent::TerminalErrorexit code field and dispatchprocess.emit("exit")on worker termination so exit handlers can modify the final code.process._fatalExceptionfor uncaught exception handling, including exit code 6 when monkey-patched to not be a function (kInvalidFatalExceptionMonkeyPatching).Fixes
test-worker-exit-code.js— all 11 test cases now pass:process.exitCodeassignment (case 0)process.exit(code)(cases 1-2)_fatalException = undefined→ exit code 6 (case 10)Test plan
cargo test --test node_compat parallel -- --filter test-worker-exit-code.js— all 11 cases passtest-worker-event.js,test-worker-process-argv.js— still pass (no regression)test-process-uncaught-exception-monitor.jsfailure is pre-existing (fails on baseline too)🤖 Generated with Claude Code