Skip to content

Conversation

Jarred-Sumner
Copy link
Collaborator

What does this PR do?

How did you verify your code works?

@robobun
Copy link
Collaborator

robobun commented Sep 19, 2025

Updated 5:31 AM PT - Sep 19th, 2025

@Jarred-Sumner, your commit 2bb9f3a has 2 failures in Build #26331 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 22796

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

bun-22796 --bun

Copy link
Contributor

coderabbitai bot commented Sep 19, 2025

Walkthrough

Updates 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

Cohort / File(s) Summary of Changes
UDP socket error handling cleanup
packages/bun-usockets/src/bsd.c
Removed a non-functional comment. Added resource cleanup on errors: close listenFd when bsd_set_reuse fails; freeaddrinfo(result) and close listenFd when IPV6_V6ONLY handling fails. No public API changes.

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description contains only the template headings with no substantive content, so it does not satisfy the repository template sections "What does this PR do?" and "How did you verify your code works?" and therefore is incomplete. Populate "What does this PR do?" with a concise summary of the fix (e.g., add bsd_close_socket() on error paths for UDP SO_REUSEPORT conflicts and the affected file path), and populate "How did you verify your code works?" with concrete verification steps including tests run, commands to reproduce, test outputs or CI links, and platforms tested; update the PR body with these details before requesting review.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly and accurately describes the primary change: adding a missing close call when SO_REUSEPORT causes a UDP socket conflict, which matches the raw_summary showing added bsd_close_socket() on error paths in the UDP socket creation code. It is concise, on-topic, and readable for a reviewer scanning the PR history.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jarred/socket-close-udp

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 5102538 and 2bb9f3a.

📒 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.

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.

2 participants