http: resume kept-alive when no body allowed - #52329
Conversation
|
Review requested:
|
| if (!shouldKeepAlive) { | ||
| req.shouldKeepAlive = false; | ||
| } | ||
|
|
There was a problem hiding this comment.
Please remove this space.
|
Setting to draft, went to fix review nit and add tests and I am not convinced issue is fully resolved. |
2de97af to
be6b085
Compare
|
@ShogunPanda I added tests and discovered that my approach putting the logic in in an |
be6b085 to
2dee82a
Compare
|
This is potentially unsafe. Some servers don't properly end |
|
@ronag re-using a socket following a HEAD request is the existing logic. I checked with the following replication: gives: and Should I take a look at that first before returning to this PR? |
|
What does this PR do then? |
|
I think the problem might apply to all expected empty responses. I need to check that for undici as well. |
Makes it so the |
Sorry, I don't understand. |
|
FWIW what lead me here is a package that was using Will push changes for lint errors shortly. |
2dee82a to
8c4db34
Compare
|
In a twist of irony, my test appears to have left a socket open. Will take a look and push fix. |
8c4db34 to
cf6677a
Compare
|
Ready for ci: the server in the test needed to be unref'd. |
|
I can't replicate that final test-asan failure locally - let me know if there's anything else I need to do to get this ready to land 👍 |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Commit Queue failed- Loading data for nodejs/node/pull/52329 ✔ Done loading data for nodejs/node/pull/52329 ----------------------------------- PR info ------------------------------------ Title http: resume kept-alive when no body allowed (#52329) Author Matt Weber <hello@mweber.xyz> (@mweberxyz, first-time contributor) Branch mweberxyz:http-keep-alive-auto-resume -> nodejs:main Labels http, semver-minor, author ready, needs-ci Commits 1 - http: resume kept-alive when no body allowed Committers 1 - Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: https://github.com/nodejs/node/pull/52329 Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/52329 Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> -------------------------------------------------------------------------------- ℹ This PR was created on Tue, 02 Apr 2024 17:41:06 GMT ✔ Approvals: 5 ✔ - Paolo Insogna (@ShogunPanda) (TSC): https://github.com/nodejs/node/pull/52329#pullrequestreview-1991621837 ✔ - Matteo Collina (@mcollina) (TSC): https://github.com/nodejs/node/pull/52329#pullrequestreview-2722000587 ✔ - Robert Nagy (@ronag) (TSC): https://github.com/nodejs/node/pull/52329#pullrequestreview-1989549614 ✔ - Minwoo Jung (@JungMinu): https://github.com/nodejs/node/pull/52329#pullrequestreview-2228985328 ✔ - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/52329#pullrequestreview-2744925503 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2025-07-11T07:24:00Z: https://ci.nodejs.org/job/node-test-pull-request/67928/ - Querying data for job/node-test-pull-request/67928/ ✔ Last Jenkins CI successful ⚠ PR author is a new contributor: @mweberxyz(hello@mweber.xyz) ⚠ - commit a38c7aeac7f6 is authored by 1062734+mweberxyz@users.noreply.github.com -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncuhttps://github.com/nodejs/node/actions/runs/16581371844 |
|
Sorry to see this stall out. Can you rebase and see what might be failing in CI? Would love to help you land this! |
According to RFC9112 section 6.3.1: HEAD requests, and responses with status 204 and 304 cannot contain a message body, If a socket will be kept-alive, resume the socket during parsing so that it may be returned to the free pool. Fixes nodejs#47228
a38c7ae to
b5c8c84
Compare
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
In accordance with https://www.rfc-editor.org/rfc/rfc9112#name-message-body-length: HEAD, 1xx, 204, and 304 responses cannot contain a message body.
If a connection will be kept-alive, resume the socket during parsing so that it may be returned to the free pool, even if the caller has not consumed the known-expected-empty response.
Fixes: #47228
Note: The original source of the issue reporter's issue was due to failure to consume the response body of a 3xx request, which this change will not resolve. As an option, 3xx with a Content-Length of 0 could receive the same auto-resume treatment. I am hesitant to propose that change, as some HTTP servers may return a message body (ie
<a href=here>Moved Here</a>), which would then make the caller's responsibility to consume or resume dependent on the particular remote server's behavior.