Skip to content

fix(ext/node): fix worker exit code propagation in worker_threads#32124

Merged
bartlomieju merged 2 commits intodenoland:mainfrom
bartlomieju:fix/worker-exit-code
Feb 12, 2026
Merged

fix(ext/node): fix worker exit code propagation in worker_threads#32124
bartlomieju merged 2 commits intodenoland:mainfrom
bartlomieju:fix/worker-exit-code

Conversation

@bartlomieju
Copy link
Copy Markdown
Member

Summary

  • Properly propagate process.exitCode from Node worker_threads to the parent, matching Node.js behavior. Previously exit codes were hardcoded to 0 (natural exit) or 1 (error exit), ignoring process.exitCode set by the worker.
  • Add WorkerControlEvent::TerminalError exit code field and dispatch process.emit("exit") on worker termination so exit handlers can modify the final code.
  • Implement process._fatalException for 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.exitCode assignment (case 0)
  • process.exit(code) (cases 1-2)
  • Uncaught exception with/without handlers (cases 3-9)
  • _fatalException = undefined → exit code 6 (case 10)

Test plan

  • cargo test --test node_compat parallel -- --filter test-worker-exit-code.js — all 11 cases pass
  • test-worker-event.js, test-worker-process-argv.js — still pass (no regression)
  • Verified test-process-uncaught-exception-monitor.js failure is pre-existing (fails on baseline too)

🤖 Generated with Claude Code

bartlomieju and others added 2 commits February 11, 2026 09:53
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>
Copy link
Copy Markdown
Member

@littledivy littledivy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bartlomieju bartlomieju merged commit 1b2a9f1 into denoland:main Feb 12, 2026
23 checks passed
@bartlomieju bartlomieju deleted the fix/worker-exit-code branch February 12, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants