-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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 request setTimeout(0) does not remove timeout listener #25499
Comments
@nodejs/http |
Is there any reason for using This re-adds the listener right after it is removed Lines 591 to 594 in 968e901
because the I think we can make diff --git a/lib/_http_client.js b/lib/_http_client.js
index 95488bc5e7..2e9d22389d 100644
--- a/lib/_http_client.js
+++ b/lib/_http_client.js
@@ -731,6 +731,9 @@ function _deferToConnect(method, arguments_, cb) {
}
ClientRequest.prototype.setTimeout = function setTimeout(msecs, callback) {
+ if (this._ended)
+ return this;
+
listenSocketTimeout(this);
msecs = validateTimerDuration(msecs);
if (callback) this.once('timeout', callback); |
When the response ends (or the user cancels the request), |
And even if @szmarczak didn't have a valid reason to do so, a bit of state checking that prevents the memory leak would be cool. 🙂 |
Yes I agree. If you have some spare time to open a PR please do. |
Spare time is debatable but I've created #25536. (Sorry about the force-push spam.) |
Fixes: nodejs#25499 Originally discovered and resolved by @szmarczak.
Originally discovered and resolved by @szmarczak. PR-URL: #25536 Fixes: #25499 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Originally discovered and resolved by @szmarczak. PR-URL: #25536 Fixes: #25499 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Originally discovered and resolved by @szmarczak. PR-URL: #25536 Fixes: #25499 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Originally discovered and resolved by @szmarczak. PR-URL: #25536 Fixes: #25499 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This was originally discovered by @szmarczak and reported as sindresorhus/got#690.
Unless we're mistaken,
setTimeout(0)
on an HTTP request (and then socket) can lead to atimeout
listener not being removed. This is problematic because combined with a keepalive agent, it can lead to a memory leak.This Gist by Szymon illustrates the issue. For convenience, I'm also quoting his inline explanation here:
The text was updated successfully, but these errors were encountered: