Repository navigation
udp: stop setting IP_RECVERR on UDP sockets #35922
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
12
commits into
main
Choose a base branch
from
farm/51070a88/udp-errqueue-not-fatal
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.
+570
−188
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
51b2b71
udp: stop IP_RECVERR on unconnected sockets; never fatal-by-default f…
robobun 6940a41
[autofix.ci] apply automated fixes
autofix-ci[bot] 2913919
trim on_recv_error comment
robobun 017df5e
address review: drop dead LIBUS_UDP_LINUX_RECVERR flag and s->connect…
robobun 3cd59d6
drop stale 'can still send' from test comment
robobun 48081ba
wrap connected-to-dead-port send in try/catch to match siblings
robobun 339adb0
refresh stale loop.c comment now that connect() arms IP_RECVERR on ad…
robobun 4c02d00
Merge main; take main's side for every file
robobun fce92ac
udp: never set IP_RECVERR
robobun 392de3b
udp: shorten two comments in on_recv_error, wait on the event loop in…
robobun 826d5d0
test(udp): wait for the pending error before the step that depends on it
robobun b374bbe
test(udp): import the dgram internals at module scope, run the ::1 ec…
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
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.
🔴 Linux users of an unconnected Bun.udpSocket no longer get an ECONNREFUSED
errorcallback for a datagram sent to a closed port, a feature released in 1.3.12. bsd.c:1629 sets IP_RECVERR on no socket, so the kernel drops ICMP port-unreachable for unconnected sockets and the handler never runs; on the base branch it ran once per refused datagram. This follows from the stated purpose and the PR flags it for a maintainer. Fix: the call is the maintainer's; within the purpose, arm IP_RECVERR only for a Bun.udpSocket that registers anerrorhandler (never node:dgram or node:quic), accepting the poisoned next send on those sockets.Why this was flagged
A Linux program calls Bun.udpSocket({ socket: { error(...) {} } }) without
connectand sends to a port nothing listens on. The kernel's __udp4_lib_err only records an ICMP error on a socket without IP_RECVERR when the socket is connected and the error is hard, so the unconnected socket never raises EPOLLERR. packages/bun-usockets/src/bsd.c:1629 (bsd_apply_udp_recv_options) no longer sets IP_RECVERR or IPV6_RECVERR, so src/runtime/socket/udp_socket.rs:98 on_recv_error is never reached for that socket. On the base branch us_create_udp_socket set the option for every Rust-created socket, loop.c drained MSG_ERRQUEUE and called on_recv_error for each refused datagram, and the Bun.udpSocketerrorhandler received ECONNREFUSED (the base test at test/js/bun/udp/udp_socket_recv_flags.test.ts asserted exactly that; this PR replaces it with an assertion that errors stay []). The user gets silence instead of a report and no error, warning or type change tells them. The PR's Downsides section names this cost and asks for a maintainer's decision.Verification: The PR description's "Downsides" section states "On Linux an unconnected
Bun.udpSocketno longer getsECONNREFUSEDinerrorfor a closed port". At packages/bun-usockets/src/bsd.c:1629 the IP_RECVERR setsockopt block is deleted. The PR deletes the existing testtest/js/bun/udp/udp_socket_recv_flags.test.tsand replaces it with one assertingerrors: []for an unconnected sender.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 is the intended trade and the maintainer's call. The PR body names it under Downsides. Arming IP_RECVERR only for a Bun.udpSocket with an error handler does not avoid the cost: the kernel records the ICMP error on the socket either way, so the next send to any peer fails with it and a reply server still breaks on the first client that closes its port. libuv and Node do not set the option, and the connected-socket report stays.