Repository navigation
node:cluster: one handle for each descriptor that workers name #44185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
robobun
wants to merge
9
commits into
main
Choose a base branch
from
robobun/148c7915/cluster-one-handle-per-fd
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1a66fff
node:cluster: refuse a descriptor of the wrong kind in the primary
robobun c1c3060
ci: retrigger
robobun 1a667c8
node:cluster test: a SCHED_RR row for a descriptor that is not an int…
robobun 23018e9
node:cluster: complete the SAFETY comment of the getsockopt call
robobun 0a3c66d
node:cluster: one handle for each descriptor that workers name
robobun f7522d2
node:cluster: look up the holder of a descriptor on every platform
robobun 677572e
Merge remote-tracking branch 'origin/main' into robobun/148c7915/clus…
robobun c0924e1
node:cluster test: a refused ask between two asks for one descriptor,…
robobun 8810596
node:cluster test: end the disconnect test at once after a wrong answer
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟣 pre-existing, not blocking: pre-existing: a primary that itself listens on an inherited descriptor and whose worker names the same number still loses that listener and closes the number twice, exactly as on the base branch. The holder lookup in errnoOfFdQuery at primary.ts:246-253 only sees the dgram registry and the entries of
handles; a net.Server or Bun.listen listener of the primary is not a holder it can see, so a SharedHandle adopts the descriptor and closes it when the worker leaves. Fix: treat a descriptor that a live listener of the primary holds as held too, returning EEXIST like the other holders; the PR description lists this under "Not covered".A small fix can ride a push you are already making; otherwise a short reply is enough.
Why this was flagged
Trigger: in the primary, net.createServer().listen({ fd: 3 }), then a worker calls server.listen({ fd: 3 }) under SCHED_NONE (or tls under SCHED_RR). queryServer reaches errnoOfFdQuery at src/js/internal/cluster/primary.ts:246; handles.$forEach at primary.ts:251-253 finds no handle because the primary's own net.Server is not in
handles. errnoOfFdQuery returns 0, and primary.ts:325 constructs a SharedHandle; SharedHandle.ts:22 validateFd(3, false) passes and SharedHandle.ts:26 records { fd: 3 }. When the worker closes its server, close() at primary.ts:376-383 calls remove(), and SharedHandle.ts:67 closeRawHandle(3) closes the descriptor that the primary's own listener still polls; the primary's server silently stops accepting, and its later server.close() closes number 3 a second time. The base branch behaves the same; the diff adds the holder lookup but it cannot see this holder. No safeguard covers it: validateFd checks kind and connectedness only.Verification: Trigger: the primary does net.createServer().listen({ fd: N }) and a worker calls listen({ fd: N }) under SCHED_NONE. That listener is never inserted into
handles, so the holder lookup in errnoOfFdQuery (src/js/internal/cluster/primary.ts:249-253) finds nothing and returns 0. SharedHandle.remove (SharedHandle.ts:67) calls closeRawHandle(fd), closing the descriptor under the primary's live listener.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case is real. It is the first entry under "Not covered" in the PR body, and I left it out of this PR on purpose.
I measured it with release builds. The primary listens on descriptor 3 with its own
net.Server. One worker underSCHED_NONEcallslisten({ fd: 3 })and closes its server when it listens. Then a client connects.bind EEXISTlisteningEBADF, the client gets no answerlisteningNode has this answer from libuv:
uv_tcp_openreturnsUV_EEXISTfor a descriptor that its loop watches already (tcp.c). The cluster code of Bun cannot see a listener that it did not make. A walk over the listen sockets of the loop can see it, but that is native code inpackages/bun-usockets. This PR changes three builtin JS files and no native code, so that lookup is a change of its own.