Skip to content

fix socket.write() dropping data#28871

Open
a1pl wants to merge 7 commits intooven-sh:mainfrom
a1pl:main
Open

fix socket.write() dropping data#28871
a1pl wants to merge 7 commits intooven-sh:mainfrom
a1pl:main

Conversation

@a1pl
Copy link
Copy Markdown

@a1pl a1pl commented Apr 4, 2026

uhh so my web server wasnt working like at all on bun but worked just fine on node.
i cloned bun, fixed it, then wrote a test.

Copy link
Copy Markdown
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1bb038d0-7972-4bd3-9dd9-1005cc667161

📥 Commits

Reviewing files that changed from the base of the PR and between 39604e2 and a95f31b.

📒 Files selected for processing (2)
  • scripts/build/CLAUDE.md
  • test/js/node/http/node-http-upgrade-socket-write.test.ts

Walkthrough

Enables socket streaming for HTTP upgrade connections by calling socket[kEnableStreaming](true) before emitting "upgrade". Adds a new test file with three tests validating upgrade-socket write/pipe behavior. Removes the zig.buildOnSave workspace setting from workspace.code-workspace.

Changes

Cohort / File(s) Summary
HTTP Upgrade Socket Streaming
src/js/node/_http_server.ts
In the upgrade control flow, explicitly enables socket streaming via socket[kEnableStreaming](true) before emitting the "upgrade" event.
HTTP Upgrade Socket Tests
test/js/node/http/node-http-upgrade-socket-write.test.ts
Adds three tests exercising upgrade handling using raw Upgrade: websocket requests: verifies socket.write() return and bytesWritten, verifies combined 101 response plus payload reception, and validates socket.pipe()/echo behavior on upgrade sockets.
Workspace Configuration
workspace.code-workspace
Removes the zig.buildOnSave workspace setting from workspace settings (no replacement added in this diff).
🚥 Pre-merge checks | ✅ 1 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is missing the required structure from the template. It lacks dedicated 'What does this PR do?' and 'How did you verify your code works?' sections with proper formatting and detail. Restructure the description to follow the template with clear sections: 'What does this PR do?' explaining the socket.write() fix and streaming enablement, and 'How did you verify your code works?' documenting the three test cases added.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix socket.write() dropping data' directly and specifically describes the main change: enabling socket streaming for HTTP upgrade connections to prevent data loss during socket.write() operations.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown
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: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test/js/node/http/node-http-upgrade-socket-write.test.ts`:
- Around line 128-143: The test titled "socket.pipe() works with upgrade
sockets" does not actually call socket.pipe; update the test inside the
server.on("upgrade", (req, socket, head) => { ... }) handler to use
socket.pipe(socket) instead of the manual socket.on("data", chunk =>
socket.write(chunk)) or else rename the test to reflect the current behavior
(e.g., "upgrade socket echoes data"); also fix the typo "recieved" to "received"
in the handler comment.
- Around line 4-66: The test opens resources (server via createServer/listen and
a raw connection via Bun.connect assigned to conn) but doesn't guarantee cleanup
if clientDone rejects; wrap the server and connection lifecycle in a
deterministic cleanup block (use await using/disposable for Bun.connect and
server if available, or a try/finally) so that conn.end() and server.close()
always run; locate the upgrade test (the test named "socket.write() works in
upgrade event handler", references to createServer, server.listen, Bun.connect,
conn, clientDone) and ensure resources are disposed in finally/using to avoid
leaking the server or socket on failures.

In `@workspace.code-workspace`:
- Line 94: The change adds an unrelated IDE setting "zig.buildOnSaveProvider":
false into the workspace config; remove this accidental local preference from
the commit by reverting or deleting that JSON key so the PR only contains the
socket.write() HTTP upgrade fix (look for the "zig.buildOnSaveProvider" entry in
the workspace configuration and remove it or revert that file to its previous
state).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 303de33e-c5d1-48a9-819a-c4e8d9b7d837

📥 Commits

Reviewing files that changed from the base of the PR and between d27d84f and 0674044.

📒 Files selected for processing (3)
  • src/js/node/_http_server.ts
  • test/js/node/http/node-http-upgrade-socket-write.test.ts
  • workspace.code-workspace

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.

1 participant