-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Add missing close call when SO_REUSEPORT is used for UDP socket and there's a conflict #22796
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
base: main
Are you sure you want to change the base?
Conversation
…here's a conflict
Updated 5:31 AM PT - Sep 19th, 2025
❌ @Jarred-Sumner, your commit 2bb9f3a has 2 failures in
🧪 To try this PR locally: bunx bun-pr 22796 That installs a local version of the PR into your bun-22796 --bun |
WalkthroughUpdates in packages/bun-usockets/src/bsd.c adjust error handling in bsd_create_udp_socket by adding socket closure and addrinfo cleanup on specific failure paths and removing a non-functional comment. No public API changes. Changes
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests
Comment |
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
packages/bun-usockets/src/bsd.c (2)
1220-1224
: Propagate and preserve err before cleanup on bsd_set_reuse failure.Today the function drops the specific failure code. Capture errno/WSAGetLastError before free/close and assign to err so callers can diagnose why SO_REUSEPORT/addr reuse failed.
- if (bsd_set_reuse(listenFd, options) != 0) { - freeaddrinfo(result); - bsd_close_socket(listenFd); - return LIBUS_SOCKET_ERROR; - } + if (bsd_set_reuse(listenFd, options) != 0) { +#ifdef _WIN32 + int saved_err = WSAGetLastError(); +#else + int saved_err = errno; +#endif + freeaddrinfo(result); + bsd_close_socket(listenFd); + if (err) { *err = saved_err; } + return LIBUS_SOCKET_ERROR; + }
1227-1233
: Also set err on IPV6_V6ONLY failure (and preserve before cleanup).Same rationale: return path should propagate the setsockopt failure code.
- if (setsockopt(listenFd, IPPROTO_IPV6, IPV6_V6ONLY, &enabled, sizeof(enabled)) != 0) { - freeaddrinfo(result); - bsd_close_socket(listenFd); - return LIBUS_SOCKET_ERROR; - } + if (setsockopt(listenFd, IPPROTO_IPV6, IPV6_V6ONLY, &enabled, sizeof(enabled)) != 0) { +#ifdef _WIN32 + int saved_err = WSAGetLastError(); +#else + int saved_err = errno; +#endif + freeaddrinfo(result); + bsd_close_socket(listenFd); + if (err) { *err = saved_err; } + return LIBUS_SOCKET_ERROR; + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
packages/bun-usockets/src/bsd.c
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Format
🔇 Additional comments (1)
packages/bun-usockets/src/bsd.c (1)
1220-1231
: Good fix — UDP FD + addrinfo cleanup verified.
All error paths in bsd_create_udp_socket now call freeaddrinfo(result) and bsd_close_socket(listenFd) before returning; no FD leaks found.
What does this PR do?
How did you verify your code works?