Skip to content

worker: emit worker exit notifications on BroadcastChannel - #65575

Open
SudhansuBandha wants to merge 5 commits into
nodejs:mainfrom
SudhansuBandha:worker-lifecycle-broadcast-channel
Open

SudhansuBandha wants to merge 5 commits into
nodejs:mainfrom
SudhansuBandha:worker-lifecycle-broadcast-channel

Conversation

@SudhansuBandha

Copy link
Copy Markdown
Contributor

Expose worker termination notifications through BroadcastChannel so consumers can observe when a worker exits and inspect its thread ID and exit code.

Fixes: #59053

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. worker Issues and PRs related to the worker_threads module and Worker API. labels Aug 27, 2026
@codecov

codecov Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.26027% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.72%. Comparing base (3ea9547) to head (59dac08).

Files with missing lines Patch % Lines
src/node_messaging.cc 96.72% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #65575      +/-   ##
==========================================
+ Coverage   90.71%   90.72%   +0.01%     
==========================================
  Files         801      801              
  Lines      280705   280771      +66     
  Branches    54168    54174       +6     
==========================================
+ Hits       254640   254728      +88     
+ Misses      16247    16213      -34     
- Partials     9818     9830      +12     
Files with missing lines Coverage Δ
lib/internal/worker/io.js 99.24% <100.00%> (+<0.01%) ⬆️
src/node_messaging.h 72.00% <100.00%> (+8.84%) ⬆️
src/node_messaging.cc 83.48% <96.72%> (+0.69%) ⬆️

... and 30 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@SudhansuBandha
SudhansuBandha force-pushed the worker-lifecycle-broadcast-channel branch from 4dd297f to d8a79bf Compare August 27, 2026 15:04
Comment thread doc/api/worker_threads.md Resolved
Comment thread src/node_messaging.cc Resolved
Comment thread src/node_messaging.cc Resolved
Comment thread src/node_messaging.cc Resolved
@SudhansuBandha

Copy link
Copy Markdown
Contributor Author

HandleScope handle_scope(env()->isolate());

HandleScope handle_scope(env()->isolate());

I have observed the same line being present twice in OnMessage handler I have kept the first and removed the second. If this is not to be done then please let me know @addaleax I will revert it.

@SudhansuBandha
SudhansuBandha force-pushed the worker-lifecycle-broadcast-channel branch from f23efdb to b1c9fb9 Compare September 3, 2026 15:22
@MikeMcC399

This comment was marked as resolved.

@SudhansuBandha
SudhansuBandha force-pushed the worker-lifecycle-broadcast-channel branch from b1c9fb9 to f3007df Compare September 18, 2026 08:23
@MikeMcC399

This comment was marked as resolved.

@SudhansuBandha

Copy link
Copy Markdown
Contributor Author

@MikeMcC399
I ran the full Windows test suite against my PR. The suite completed with 7346 passing and 46 failures. Most of the failures are Windows environment-specific: symlink tests fail with EPERM, and some tests invoking Unix utilities failed because cat/head were unavailable in my development Windows environment.

I have not received any failure on my Windows machine because of my changes in PR. Can you provide me a suitable approach where I can recreate the CI failure on Windows machine. Will WSL/MSYS2 help in this regards?

@MikeMcC399

This comment was marked as resolved.

@MikeMcC399

This comment was marked as resolved.

@SudhansuBandha

Copy link
Copy Markdown
Contributor Author

Thank you @MikeMcC399 for your help. I believe I have missed a failing test in my changes which I am currently looking at it. Hopefully CI issues will get resolved after this.

@SudhansuBandha
SudhansuBandha force-pushed the worker-lifecycle-broadcast-channel branch 2 times, most recently from c1b0497 to ccc39ae Compare September 28, 2026 15:47
@SudhansuBandha

SudhansuBandha commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor Author

@MikeMcC399 I have fixed the failing test but still the CI issue is not getting resolved. If it is possible, can you or anyone else debug these failing CI issues against the test suite on Linux/MacOs. I am not able to reproduce on Windows and due to limited hardware resources it is difficult for me to have a dual setup of Windows and Linux on my machine

@MikeMcC399

Copy link
Copy Markdown
Member

I'm sorry, I won't be able to help you further with the test problems.

@SudhansuBandha
SudhansuBandha force-pushed the worker-lifecycle-broadcast-channel branch from 83e569e to c0f9084 Compare October 5, 2026 15:24
@SudhansuBandha

Copy link
Copy Markdown
Contributor Author

@MikeMcC399 CI looks to be good for now. Hope that we can take this further!!!😄

@MikeMcC399

Copy link
Copy Markdown
Member

CI looks to be good for now. Hope that we can take this further!!!😄

Perhaps @addaleax will be able to review again now that your tests are succeeding?

@SudhansuBandha

Copy link
Copy Markdown
Contributor Author

CI looks to be good for now. Hope that we can take this further!!!😄

Perhaps @addaleax will be able to review again now that your tests are succeeding?

I am also hopeful for the same!!

@SudhansuBandha

Copy link
Copy Markdown
Contributor Author

Hey @addaleax , hope all is good. As per your feedback, suggested changes are implemented. CI is also good. Do review them whenever you have a moment and let me know if there needs any improvement.

@SudhansuBandha
SudhansuBandha force-pushed the worker-lifecycle-broadcast-channel branch from c0f9084 to bdcce46 Compare October 27, 2026 16:26
@SudhansuBandha
SudhansuBandha force-pushed the worker-lifecycle-broadcast-channel branch from bdcce46 to 3231711 Compare November 12, 2026 04:11
Expose worker termination notifications through BroadcastChannel
so consumers can observe when a worker exits andinspect
its thread ID and exit code.

Fixes: nodejs#59053
Signed-off-by: SudhansuBandha <bandhasudhansu@gmail.com>
@SudhansuBandha
SudhansuBandha force-pushed the worker-lifecycle-broadcast-channel branch from 3231711 to 59dac08 Compare November 18, 2026 02:19
@SudhansuBandha

SudhansuBandha commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi, wanted to check if this PR could get some movement. @jasnell, given your prior work on BroadcastChannel, would you be willing to take a look whenever you have a moment? All previous feedback has been addressed and the branch is rebased.

Comment thread doc/api/worker_threads.md
-->

* Type: {Function} Invoked when worker associated with the
`BroadcastChannel` terminates.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is the use case for this primarily diagnostic? If so, I wonder if a diagnostic channel event would be better?

@SudhansuBandha SudhansuBandha Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For now, primary consumers are most likely APM/observability tools like Prometheus (as described in the original issue), diagnostics channel event does seem to be a good fit. I’m less familiar with the conventions around diagnostics channel, so I’d welcome your guidance for the correct approach to take this forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. worker Issues and PRs related to the worker_threads module and Worker API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BroadcastChannel doesn't fill in useful MessageEvent fields like source, or ports

5 participants