Skip to content

http: keep forwarding socket 'drain' after response completes - #67780

Open
mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:fix-http-drain-after-response
Open

mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:fix-http-drain-after-response

Conversation

@mcollina

Copy link
Copy Markdown
Member

When a server responds before it has read the whole request body, the client
stops forwarding the socket's 'drain' event to the request as soon as the
response is complete. A writer that honors backpressure, such as a stream
piped into the request, then never receives 'drain', never calls end(),
and the socket keeps the process alive.

socketOnData() removed the 'drain' listener as soon as parser.incoming
was complete, without checking whether the request was still writing and
waiting for 'drain'. With this change the listener stays attached until the
request has ended and is removed in responseKeepAlive() when the socket is
released back to the pool.

Fixes: #67763

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/http
  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added http Issues and PRs related to the http subsystem. needs-ci PRs that need a full CI run. labels Nov 25, 2026
@mcollina
mcollina force-pushed the fix-http-drain-after-response branch from e2cac06 to c7bdb39 Compare November 25, 2026 16:09
When a server responds before it has read the whole request body, the
client stops forwarding the socket's 'drain' to the request as soon as
the response is complete. A writer that honors backpressure, such as a
stream piped into the request, then never receives 'drain', never calls
end(), and the socket keeps the process alive.

Keep the 'drain' listener until the request has ended and remove it in
responseKeepAlive() when the socket is released back to the pool.

Fixes: nodejs#67763
Signed-off-by: Matteo Collina <matteo.collina@gmail.com>
@mcollina
mcollina force-pushed the fix-http-drain-after-response branch from c7bdb39 to 91f2665 Compare November 25, 2026 16:42
@codecov

codecov Bot commented Nov 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.50%. Comparing base (d5570d9) to head (91f2665).
⚠️ Report is 129 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67780      +/-   ##
==========================================
- Coverage   90.61%   90.50%   -0.11%     
==========================================
  Files         801      805       +4     
  Lines      281090   285784    +4694     
  Branches    54258    55172     +914     
==========================================
+ Hits       254706   258663    +3957     
- Misses      16567    17216     +649     
- Partials     9817     9905      +88     
Files with missing lines Coverage Δ
lib/internal/http/client.js 97.12% <100.00%> (+0.01%) ⬆️

... and 100 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

http Issues and PRs related to the http subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

http: client stops forwarding socket 'drain' to the request once the response is complete

2 participants