Commit 697bdb1
fix: send BroadcastChannel messages before close (#34628)
Fixes a race where BroadcastChannel.postMessage deferred the
cross-worker send and then skipped it if the channel was closed before
the deferred callback ran. This made node:worker_threads
BroadcastChannel examples that call close() immediately after
postMessage() hang waiting for a message that was never sent.
The send is now committed to the shared broadcast queue before
postMessage() returns, while receiver dispatch remains asynchronous.
Added a node:worker_threads regression spec for the reported repro.
Closes denoland/divybot#362
Fixes #31134
Verification:
- timeout 10s target/debug/deno run --allow-all
--unstable-broadcast-channel /tmp/orchid-362-repro.mjs
- env -u RUSTC_WRAPPER cargo test -p specs_tests
specs::node::worker_threads::broadcast_channel -- --nocapture
- target/debug/deno fmt --check
tests/specs/node/worker_threads/__test__.jsonc
tests/specs/node/worker_threads/broadcast_channel.mjs
- git diff --check
Note: ./tools/format.js --check on the touched files spawned dprint
plugin processes that did not exit in this workspace after reporting the
initial import formatting diff; the reported diff was applied, and the
new spec files pass deno fmt --check.
Co-authored-by: divybot <divybot@users.noreply.github.com>
Co-authored-by: Divy Srivastava <me@littledivy.com>1 parent d11c5d0 commit 697bdb1
3 files changed
Lines changed: 23 additions & 6 deletions
File tree
- ext/web
- tests/specs/node/worker_threads
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
147 | 145 | | |
148 | 146 | | |
149 | 147 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
37 | 42 | | |
38 | 43 | | |
39 | 44 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
0 commit comments