Skip to content

fix(ext/node): keep event loop alive for worker message listeners after unref#33076

Open
bartlomieju wants to merge 1 commit intomainfrom
fix/worker-threads-unref-message
Open

fix(ext/node): keep event loop alive for worker message listeners after unref#33076
bartlomieju wants to merge 1 commit intomainfrom
fix/worker-threads-unref-message

Conversation

@bartlomieju
Copy link
Copy Markdown
Member

Summary

  • worker.unref() was unconditionally unrefing the message receive promise, causing the event loop to exit even when there were active message listeners
  • Now tracks whether there are message listeners and keeps the message promise refed as long as listeners exist, matching Node.js behavior
  • Overrides on/off/addListener/removeListener/removeAllListeners to update the ref state when message listeners change

Closes #33061

Test plan

  • ./x test-node worker_threads_test passes
  • Manual verification: repro from worker_threads behavior different from node #33061 consistently prints "done"
  • unref() without message listeners still allows process exit
  • once('message') correctly unrefs after the listener fires

🤖 Generated with Claude Code

…er unref

worker.unref() was unconditionally unrefing the message receive promise,
causing the event loop to exit even when there were active "message"
listeners. This didn't match Node.js behavior where message listeners
keep the event loop alive regardless of the worker's ref state.

Track whether there are "message" listeners and keep the message promise
refed as long as listeners exist. Override on/off/addListener/
removeListener/removeAllListeners to update the ref state when message
listeners are added or removed.

Closes #33061

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
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.

worker_threads behavior different from node

1 participant