Repository navigation
Conversation
|
Status How I reproduced it: a parent process binds a socket and starts a cluster primary with that socket as descriptor 3. Each worker calls
The stack:
#45186 contains this change, with the same primary fixture and 4 of the 5 tests. It also sends every other |
e6e470c to
36cc358
Compare
fe10c3e to
f8e07c7
Compare
|
Updated 9:36 AM PT - Oct 25th, 2026
✅ @robobun, your commit 0fa6dc8e15bedc4d9058b434b968481803526b14 passed in 🧪 To try this PR locally: bunx bun-pr 44015That installs a local version of the PR into your bun-44015 --bun |
36cc358 to
89570a0
Compare
f8e07c7 to
d79722c
Compare
There was a problem hiding this comment.
Findings marked 🟡 are optional suggestions and need no follow-up push.
Still open from earlier reviews (10):
- 🔴
src/js/node/_http_server.ts:728—A worker that re-listens on a descriptor after close(cb) and is then disconnected by the primary never finishes disconn… - Also unresolved: 9 minor or pre-existing.
If you have decided not to act on one of these findings, resolve its thread (a reply alone leaves it open) and the next review stops counting it. To review this commit again now, use Re-run on its "Claude Code Review" check.
89570a0 to
667efbc
Compare
d79722c to
9450e1e
Compare
|
@robobun wake up!! |
|
@robobun wake up!! |
667efbc to
3ad7c22
Compare
9450e1e to
ff219da
Compare
|
I rebased this PR onto the new head of #44013. The new head is What the rebase changed:
Checked on the new head with a debug build on Linux x64: the 4 cluster tests in |
3ad7c22 to
ad8ca73
Compare
ff219da to
5d2d093
Compare
ad8ca73 to
53cec12
Compare
5d2d093 to
c6d5fa8
Compare
53cec12 to
682a069
Compare
c6d5fa8 to
4628864
Compare
682a069 to
fa5b0a4
Compare
4628864 to
3ac1862
Compare
fa5b0a4 to
6ef0ac4
Compare
3ac1862 to
5132d14
Compare
6ef0ac4 to
1540f75
Compare
5132d14 to
ed8a9f6
Compare
1540f75 to
61d41c9
Compare
ed8a9f6 to
225b7ab
Compare
… the primary In a cluster worker the number names a descriptor of the primary, as in Node. The worker asks the primary through cluster._getServer, as net.Server does, and listens on the descriptor that the primary shares.
61d41c9 to
9aecc57
Compare
225b7ab to
0fa6dc8
Compare
There was a problem hiding this comment.
I reviewed the latest push and found no bugs; the points raised in earlier threads (listening-id bump before option validation, ExceptionWithHostPort with the bunHint note, close() queuing its callback on 'close' so _disconnect cannot throw, worker exit wired in the primary fixture, concurrent describe with the https variant) are all reflected in the code now. Because this adds a cluster-IPC handle lifecycle to http.Server and the tests could not be run on this machine, a human look at the ownership paths would still be worthwhile.
What was reviewed:
listenFdInWorkeragainstlistenInClusterin src/js/node/net.ts:4336-4400 and child.tsshared()/makeSharedHandle: every branch (late answer, errno/no sharedFd, kRealListen throw, success) pairs the handle withclose()and clearskClusterOwner;adopted = trueonly after kRealListen succeeds, matching net.ts.close()in a worker:kClusterListeningId++precedes the not-running early return (so a close() before the answer invalidates it, as Node's_listeningId++), andreleaseClusterHandleruns only once a listener existed;_disconnectcallingowner.close(cb)resolves viaonce("close").- Fixture ordering: the primary's SharedHandle.add replies synchronously, so the queryServer answer always precedes the "echo" reply and the act:close precedes each worker's final message, making the
fd: "closed"assertions deterministic. - Test matrix covers http/https, close vs cluster.disconnect, early close and early throwing listen, and the primary-side EINVAL error path; no per-test timeouts, describe.concurrent,
await usingbefore assertions.
Extended reasoning...
The change adds a listenFdInWorker path to src/js/node/_http_server.ts (57 lines) so a cluster worker's http.Server.listen({ fd }) obtains the primary's shared socket via cluster._getServer, plus per-server kClusterHandle/kClusterListeningId state released in close(); it updates one docs line and replaces the old ENOTSUP test with a four-case matrix driven by two new fixtures. It touches no auth, crypto, or injection surface, only process-internal IPC handle ownership between cluster primary and worker. The code mirrors the existing net.ts listenInCluster pattern closely and the test matrix is thorough, but the handle lifecycle across close/disconnect/late-answer paths is subtle, the tests could not be executed in this environment (PR evidence also defers to CI), and a maintainer commented mid-thread with content not visible here, so a human review remains worthwhile rather than approving outright.
Part of #22559
Stacked on #44013. #45186 contains this change.
Problem
http.Server.listen({ fd })in anode:clusterworker emitsENOTSUP. In Node the number names a descriptor of the primary, and each worker listens on it.Server.prototype.listen(src/js/node/_http_server.ts) must ask the primary, aslistenInClusterdoes (src/js/node/net.ts:4250).Fix
cluster._getServerand passes the descriptor that it receives toBun.serve({ fd }).close()and a disconnect tell the primary that the worker left. When the last worker leaves, the primary closes its descriptor, as in Node.close()or one morelisten(), also one that throws.serve-listen.test.ts(5 tests fail on the base branch, Node v26.3.0 passes the same fixtures),node-http.test.ts,cluster.test.ts.Background
SharedHandlesends the descriptor of a shared socket over that channel.sharedOnly, so the primary never answers with a round-robin handle. An http server cannot take connections that the primary accepted.ENOTSUP, which is stricter than Node. Or listen on descriptor N of the worker, which is another socket.Downsides
listen({ fd })on one descriptor in one worker make the primary close it too early. The defect is inprimary.tson main, fornet.Servertoo.listen()executes 1 more branch on a module constant andclose()2 more. EachcreateServer()stores 2 more fields._http_server.jsgrows by 1,747 B.Notes
listen()of a worker through the primary, which changes the behaviour of each http server in a cluster. This PR changes onlylisten({ fd })in a worker. If node:http: cluster workers listen through the primary's shared handle, Bun.serve({ fd }) #45186 lands, this PR is not needed.net.ts. The disconnect of a worker callsserver.close(callback). Since node:http: the server follows Node (request body, framing, response finish, lifecycle) #43557,close()registers each callback on thecloseevent, so a callback of an earlierclose()that still waits cannot make it throw.binderrors withaddress: null, as fornet.Serverin a worker. A descriptor of the primary that is not a socket givesEINVAL.clusterValidateFd(src/js/internal/cluster/SharedHandle.ts), which exists on main fornet.Server.exclusivehas no effect onlisten({ fd }): thefdbranch oflisteninlib/net.jspasses noexclusivetolistenInCluster.NODE_UNIQUE_IDin its environment and no channel listens on its own descriptor (Bun.serve({ fd }) and node:http listen({ fd }): serve on an inherited socket #44013). A child with a channel to a parent that is not a primary waits for an answer, asnet.Server.listen()does on main. node:cluster: do not pass NODE_UNIQUE_ID to a worker's Bun.spawn children #43768 is the open change for the inherited variable.179664ea89:_http_server.js101,195 to 102,942 B. The release binary embeds the file, so its text grows by the same number. Property reads perhttp.listen(options)5 to 5. The server object has 2 more fields,kClusterHandleandkClusterListeningId: 2 stores in the constructor. A worker executes 1 read and 1 store ofkClusterListeningIdperlisten()and perclose().179664ea89with no change of content. Since 2026-10-23 the worker changes its listening id right after theERR_SERVER_ALREADY_LISTENcheck, before it reads an option, which is the order oflib/net.jsin Node v26.3.0. So a secondlisten()that throws also makes the pending answer of the primary invalid. The new test row callslisten({ fd })and thenlisten({ fd: -1 }). With the old order the server listens and the row fails.--timeout 60000:serve-listen.test.ts72 pass,node-http.test.ts329 pass,node-http-server-close-drain.test.ts31 pass,cluster.test.ts41 pass. 9 cluster scripts of the Node test suite exit with 0.EINVAL, as it does outside a cluster.bun --watchkeeping the socket across the restart is not in this stack.no test proof · iteration 2 · platform-specific test(s) that do not run on this machine, deferring to CI, which covers all platforms: test/js/bun/http/serve-listen.test.ts