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
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 e2cac06 to c7bdb39 Compare November 25, 2026 16:09
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