Skip to content

node:http: extract the half-close of socket.end() into JSNodeHTTPServerSocket::halfClose() - #44243

Merged
Jarred-Sumner merged 1 commit into
mainfrom
robobun/a085ff54/node-http-socket-half-close
Sep 30, 2026
Merged

Jarred-Sumner merged 1 commit into
mainfrom
robobun/a085ff54/node-http-socket-half-close

Conversation

@robobun

@robobun robobun commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

  • The native end() of the node:http server socket holds its half-close sequence inline (jsFunctionNodeHTTPServerSocketEnd, src/jsc/bindings/node/JSNodeHTTPServerSocketPrototype.cpp:313).
  • The next PR of this stack calls the same sequence from the drain gate of uWS, for a socket.end() that waited for buffered bytes. A second copy can drift from the first.

Fix

  • Move the sequence into JSNodeHTTPServerSocket::halfClose(). The move is verbatim: pause the reads, write with ended set (this sends the FIN), resume the reads.
  • jsFunctionNodeHTTPServerSocketEnd calls it and returns its value, as before.
  • Remove the us_socket_pause and us_socket_resume declarations from the prototype file. They have no user there now.
  • Verified: the existing suites, unchanged, on a release build of this commit. The Notes block has the list and the counts.

Behaviour change: none

Background

Downsides

  • None found. Checked the release builds of main 9f70da0 and of this commit (Linux x64). The compiler inlines halfClose(): jsFunctionNodeHTTPServerSocketEnd goes from 633 to 671 bytes, and from 192 to 191 instructions. .text (58148853 bytes) and the binary (80832072 bytes) do not change.
Notes

All runs are on Linux x64, on release builds of main 9f70da0 and of this commit 7c98ad5.

Suite Result on this commit
test/js/node/http/node-http-server-socket-end-drain.test.ts 9 pass
test/js/node/http/node-http-connect.test.ts 61 pass, 2 todo
test/js/node/http/node-http-backpressure.test.ts 83 pass
test/js/node/http/node-http-pinned-write.test.ts 10 pass
test/js/node/http/node-http-server-close-drain.test.ts 28 pass
test/js/node/http/node-http.test.ts 263 pass, 1 skip
43 files of test/js/node/test/parallel/ (test-http-*, test-https-*) that start a server and end, pipeline or write on its socket 43 exit 0 (main: 43)

A debug build with ASAN of this commit alone did not run. The same suites ran on a debug build with ASAN of the second PR of the stack, which contains this change. They pass there, apart from three timeouts from the load of the host. Each of those three tests passes alone. #44244 has the list.

Method for the sizes: llvm-nm -S and llvm-objdump -d on bun-profile, llvm-size -A for .text. Every other function of the socket binding and of HttpContext has the same bytes in both builds.

…erSocket::halfClose()

The pause, shutdown and resume sequence of the native end() moves into a
member function, unchanged. A later change calls it from a second place.
@robobun

robobun commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator Author

Status

@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: oven-sh/bun/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Essentials

Run ID: 597564ae-e27f-4ac1-97c6-48c50d88524a

📥 Commits

Reviewing files that changed from the base of the PR and between 9f70da0 and 7c98ad5.

📒 Files selected for processing (3)
  • src/jsc/bindings/node/JSNodeHTTPServerSocket.cpp
  • src/jsc/bindings/node/JSNodeHTTPServerSocket.h
  • src/jsc/bindings/node/JSNodeHTTPServerSocketPrototype.cpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.


Walkthrough

The empty-buffer normal-end path now calls halfClose. That method conditionally pauses and resumes socket reads around a buffered write. Its declaration documents the half-close behavior, and the prototype file removes the pause and resume declarations.

Changes

HTTP server socket half-close

Layer / File(s) Summary
Empty-buffer half-close
src/jsc/bindings/node/JSNodeHTTPServerSocket.h, src/jsc/bindings/node/JSNodeHTTPServerSocketPrototype.cpp, src/jsc/bindings/node/JSNodeHTTPServerSocket.cpp
The normal-end path calls halfClose when the stream buffer is empty. halfClose conditionally cycles reads around a buffered write and returns its result. The prototype file removes the pause and resume declarations.

Suggested reviewers: jarred-sumner

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 7c98a

The half-close extraction has no identified behavior regression and is ready to merge after normal checks.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely identifies the main change: extracting the half-close sequence into JSNodeHTTPServerSocket::halfClose().
Description check ✅ Passed The description explains the problem, fix, behavior, background, risks, and verification results. It uses different headings from the template, but it provides the required change summary and verifica…

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

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code review found no issues

No high-confidence issues detected in this change.

@Jarred-Sumner
Jarred-Sumner merged commit a2bfbe4 into main Sep 30, 2026
7 of 8 checks passed
@Jarred-Sumner
Jarred-Sumner deleted the robobun/a085ff54/node-http-socket-half-close branch September 30, 2026 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants