-
Notifications
You must be signed in to change notification settings - Fork 5.8k
fix(ext/node): ensure 'exit' event is fired only once for worker_threads
#31231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(ext/node): ensure 'exit' event is fired only once for worker_threads
#31231
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the worker exit event handling to emit the 'exit' event based on control messages received from the worker, rather than immediately when terminate() is called. The change introduces a guard flag to ensure the exit event is only emitted once.
Key changes:
- Added
#exitedflag to track whether the exit event has been emitted - Moved exit event emission from
terminate()method to control message handlers (TerminalError and Close cases) - Exit event now emits with exit code 1 for TerminalError and 0 for normal Close
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Thanks for the PR, are there tests you could add? |
I will check the tests and add them as soon as possible. |
Tests have been added and verified locally — all passing |
worker_threads
bartlomieju
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great fix, thanks!
fix(node:worker_threads): ensure 'exit' event fires once and matches Node.js behavior
related issue:
closes #30013
The
'exit'event innode:worker_threadswas not consistently fired, or in some cases emitted multiple times, diverging from Node.js behavior.How
• Added a private
#exitedflag to prevent duplicate'exit'emissions• Emit
'exit'with code1onTerminalErrorand with code0onClose• Removed direct
'exit'emission fromterminate()— event is now triggered by host signals• Verified with both success and failure worker scenarios to ensure parity with Node.js and Bun