-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
http: resume kept-alive when no body allowed #52329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Review requested:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit. Rest LGTM.
lib/_http_client.js
Outdated
if (!shouldKeepAlive) { | ||
req.shouldKeepAlive = false; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I get it. LGTM.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
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.
@mweberxyz would you mind to rebase this on top of main? Thanks. We should try to get this landed. |
Hello all Would like to check if there is any update on 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
563fed7
to
e21ef89
Compare
@mcollina ready to go |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #52329 +/- ##
==========================================
- Coverage 89.21% 89.20% -0.01%
==========================================
Files 662 662
Lines 191976 191990 +14
Branches 36950 36957 +7
==========================================
+ Hits 171271 171273 +2
- Misses 13545 13552 +7
- Partials 7160 7165 +5
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
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, needs-ci Commits 1 - http: resume kept-alive when no body allowed Committers 1 - Matt Weber <hello@mweber.xyz> 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> ------------------------------ 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> -------------------------------------------------------------------------------- ℹ This PR was created on Tue, 02 Apr 2024 17:41:06 GMT ✔ Approvals: 4 ✔ - 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-2632844122 ✔ - 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 ✘ Last GitHub CI failed ℹ Last Full PR CI on 2025-02-03T09:29:31Z: https://ci.nodejs.org/job/node-test-pull-request/64942/ - Querying data for job/node-test-pull-request/64942/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncuhttps://github.com/nodejs/node/actions/runs/13814439471 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
res.end(); | ||
} | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: A comment explaining what this test is asserting for would be helpful.
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.