Skip to content

ipc: fifteen fixes to re-entry, handles and the lifetime of the channel - #49324

Open
alii wants to merge 18 commits into
mainfrom
ali/ipc-fixes
Open

alii wants to merge 18 commits into
mainfrom
ali/ipc-fixes

Conversation

@alii

@alii alii commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Replaces part of #49156. One commit for each fix.

Before After Test
send() ran an Array.prototype setter: use-after-free no script "setter"
Flush recursed: stack overflow loops "long backlog"
Nested loop repeated messages or panicked position in the buffer "are buffered"
Nested loop overwrote an advanced read rest copied first "nothing is buffered"
Buffers restored under a borrow after it "are restored"
Subprocess collected during a read held "nothing else keeps"
... a write: use-after-free held "write completes"
... the close: no onDisconnect held "close is reported"
Close during cluster replay: use-after-free replay stops "replays"
Rejected dgram descriptor closed twice once "dgram.Native"
Unclaimed cluster descriptor leaked closed "is closed by"
Close during serialization leaked the handle released "releases a"
Worker exit in the listener closed twice once "Worker that receives"
Socket of a rejected message leaked closed "serializer rejects:"
Worker thread took the cluster listener: abort or hang one per thread "does not take"

Visible changes: send() ignores read-only Array.prototype indexes. A nested decode error is reported once.

Cost, µs for each read, release, main and this PR: 8 x 16 KB advanced 60.1 and 62.3, 30 x 16 KB 216 and 227 (the copy), 100 small JSON messages 23.7 and 24.6 (cause not found). Between two Bun processes, 13 workloads are within noise.

Not fixed: a listening worker leaks an unclaimed descriptor, a rejected net.Server leaks one, and disconnect() drops a queued handle.

How did you verify your code works?

  • Linux, debug+ASAN: both test files pass. Fix tests fail on main; some need ASAN. Two more are pins.
  • 200 channels after a 150 KB burst: RSS as on main (release).
  • Release builds against main: handles under backpressure (124 cases), Node in both roles (109) and teardown (73) never differ stably. With nested loops they differ by the fixes, as far as read.
  • Clippy, source lints, Windows, macOS, FreeBSD type checks pass. Windows runs 3 of the 25 new tests, in CI only.

Generated by Claude Code

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Beyond the inline findings, I also checked the #[thread_local] CHILD_SINGLETON for cross-thread Strong use: the only writers are the JS-thread cluster entry points and ipc_child_singleton_deinit in src/runtime/jsc_hooks.rs, which runs at IPC close on the same thread that created the Strongs, so no cross-thread drop. The cfg(windows) write-complete branch and the clippy/rust:check-all pass were not run here; they were checked by reading only.

Extended reasoning...

The change rewrites the IPC send queue, advanced-mode read buffering, and cluster child singleton in src/runtime/ipc.rs, src/runtime/ipc_host.rs, src/runtime/node/node_cluster_binding.rs and src/js/builtins/Ipc.ts, with new tests; it touches no auth or crypto surface but does handle descriptor passing over IPC. Four confirmed findings are posted inline, so a human look is already signalled; this note only records the thread-affinity check on the new thread-local singleton.

Comment thread src/runtime/ipc.rs Resolved
Comment thread src/runtime/ipc.rs Resolved
Comment thread src/runtime/ipc_host.rs Resolved
@robobun

robobun commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator
Updated 8:31 PM PT - Nov 21st, 2026

✅ @claude, your commit 01cc90a303580b11feda0d0abe9a6fe810e26b97 passed in Build #143544! 🎉


🧪   To try this PR locally:

bunx bun-pr 49324

That installs a local version of the PR into your bun-49324 executable, so you can run:

bun-49324 --bun

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code review found no issues

No high-confidence issues detected in this change.

This branch has not been deployed

No deployments
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.

3 participants