-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
http: keepalive race condition near timeout #52649
Comments
@nodejs/http |
This comment was marked as resolved.
This comment was marked as resolved.
@EthanTuning it's possible though unlikely related to this issue. ECONNRESET is a fairly general error code for when the server closes the socket unexpectedly. This issue is concerned with when an ECONNRESET occurs in the exact same tick of the event loop as a http request resuming on an previously used socket - which seems unlikely to be reproduced repeatedly except in the kind of narrow circumstances proposed in my post. |
Is Node ignoring server sent Keep Alive hint headers on purpose? This method in Agent.prototype.keepSocketAlive = function keepSocketAlive(socket) {
socket.setKeepAlive(true, this.keepAliveMsecs);
socket.unref();
let agentTimeout = this.options.timeout || 0;
if (socket._httpMessage?.res) {
const keepAliveHint = socket._httpMessage.res.headers['keep-alive'];
if (keepAliveHint) {
const hint = RegExpPrototypeExec(/^timeout=(\d+)/, keepAliveHint)?.[1];
if (hint) {
const serverHintTimeout = NumberParseInt(hint) * 1000;
if (serverHintTimeout < agentTimeout) {
agentTimeout = serverHintTimeout;
}
}
}
}
if (socket.timeout !== agentTimeout) {
socket.setTimeout(agentTimeout);
}
return true;
}; The |
#52653 seems relevant. |
I think we should close them actually. PR? |
Oh thanks, yeah I was very unsure, but googling got me here haha! |
…lation between http1.1 servers and clients Fixes: nodejs#47130 Fixes: nodejs#52649
…lation between http1.1 servers and clients Fixes: nodejs#47130 Fixes: nodejs#52649
…lation between http1.1 servers and clients Fixes: nodejs#47130 Fixes: nodejs#52649
I realize default in this context meant two different things. Using the default http.globalAgent -- the default timeout is 5000ms. |
…lation between http1.1 servers and clients reduced likelihood of race conditions on keep-alive timeout calculation between http1.1 servers and clients and honor server keep-alive timeout when agentTimeout is not set Fixes: nodejs#47130 Fixes: nodejs#52649
…lation between http1.1 servers and clients reduced likelihood of race conditions on keep-alive timeout calculation between http1.1 servers and clients and honor server keep-alive timeout when agentTimeout is not set Fixes: nodejs#47130 Fixes: nodejs#52649
…lation between http1.1 servers and clients reduced likelihood of race conditions on keep-alive timeout calculation between http1.1 servers and clients and honor server keep-alive timeout when agentTimeout is not set Fixes: nodejs#47130 Fixes: nodejs#52649
reduce likelihood of race conditions on keep-alive timeout calculation between http1.1 servers and clients and honor server keep-alive timeout when agentTimeout is not set Fixes: nodejs#47130 Fixes: nodejs#52649
Fixes: nodejs#52649 Refs: nodejs#54293 Co-authored-by: Zanette Arrigo <[email protected]>
Fixes: nodejs#52649 Refs: nodejs#54293 Co-authored-by: Zanette Arrigo <[email protected]>
Fixes: nodejs#52649 Refs: nodejs#54293 Co-authored-by: Arrigo Zanette <[email protected]>
Fixes: #52649 Refs: #54293 Co-authored-by: Arrigo Zanette <[email protected]> PR-URL: #54863 Reviewed-By: James M Snell <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Jake Yuesong Li <[email protected]> Reviewed-By: Ethan Arrowood <[email protected]>
Fixes: #52649 Refs: #54293 Co-authored-by: Arrigo Zanette <[email protected]> PR-URL: #54863 Reviewed-By: James M Snell <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Jake Yuesong Li <[email protected]> Reviewed-By: Ethan Arrowood <[email protected]>
Fixes: #52649 Refs: #54293 Co-authored-by: Arrigo Zanette <[email protected]> PR-URL: #54863 Reviewed-By: James M Snell <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Jake Yuesong Li <[email protected]> Reviewed-By: Ethan Arrowood <[email protected]>
Fixes: #52649 Refs: #54293 Co-authored-by: Arrigo Zanette <[email protected]> PR-URL: #54863 Reviewed-By: James M Snell <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Jake Yuesong Li <[email protected]> Reviewed-By: Ethan Arrowood <[email protected]>
Fixes: #52649 Refs: #54293 Co-authored-by: Arrigo Zanette <[email protected]> PR-URL: #54863 Reviewed-By: James M Snell <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Jake Yuesong Li <[email protected]> Reviewed-By: Ethan Arrowood <[email protected]>
Fixes: #52649 Refs: #54293 Co-authored-by: Arrigo Zanette <[email protected]> PR-URL: #54863 Reviewed-By: James M Snell <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Jake Yuesong Li <[email protected]> Reviewed-By: Ethan Arrowood <[email protected]>
Fixes: #52649 Refs: #54293 Co-authored-by: Arrigo Zanette <[email protected]> PR-URL: #54863 Reviewed-By: James M Snell <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Jake Yuesong Li <[email protected]> Reviewed-By: Ethan Arrowood <[email protected]>
Fixes: nodejs#52649 Refs: nodejs#54293 Co-authored-by: Arrigo Zanette <[email protected]> PR-URL: nodejs#54863 Reviewed-By: James M Snell <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Jake Yuesong Li <[email protected]> Reviewed-By: Ethan Arrowood <[email protected]>
Fixes: nodejs#52649 Refs: nodejs#54293 Co-authored-by: Arrigo Zanette <[email protected]> PR-URL: nodejs#54863 Reviewed-By: James M Snell <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Jake Yuesong Li <[email protected]> Reviewed-By: Ethan Arrowood <[email protected]>
Version
v21.7.3
Platform
Darwin [me] 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:11:08 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T8122 arm64
Subsystem
http
What steps will reproduce the bug?
Run
server.js
:Run
client.js
:How often does it reproduce? Is there a required condition?
Fairly reliably, might take a few runs to see it, or adjust the timeouts to account for device differences.
What is the expected behavior? Why is that the expected behavior?
It is expected that (generally) every request should succeed.
What do you see instead?
In the full debug logs - http.log - the server connection close is apparent, followed by the attempt to use the closed socket for the next request:
Additional information
The server is closing the connection at it's own 1000ms timeout, but the keepAlive timers in the client either:
The issue existed prior to Node 20, but it's incidence is more pronounced now that keepAlive is defaulted to true in http.globalAgent.
A similar issue was identified in nodejs/undici#3141. Undici already had logic in place to close connections on the client side 1000ms prior to the keep-alive value provided by the server (to account for timer/transport latency) but said logic was failing to run due to an unrelated issue.
The text was updated successfully, but these errors were encountered: