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.40%. Comparing base (bbd566d) to head (c0f9084).
⚠️ Report is 4 commits behind head on main.

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   92.74%   90.40%   -2.35%     
==========================================
  Files         422      791     +369     
  Lines      193170   276057   +82887     
  Branches    29783    52983   +23200     
==========================================
+ Hits       179160   249575   +70415     
- Misses      13682    16902    +3220     
- Partials      328     9580    +9252     
Files with missing lines Coverage Ξ”
lib/internal/worker/io.js 99.24% <100.00%> (+<0.01%) ⬆️
src/node_messaging.h 72.00% <100.00%> (ΓΈ)
src/node_messaging.cc 83.81% <96.72%> (ΓΈ)

... and 498 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
Comment thread src/node_messaging.cc Outdated
Comment thread src/node_messaging.cc Outdated
Comment thread src/node_messaging.cc Outdated
@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
Contributor

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

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 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
Contributor

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?

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

4 participants