- Version: v11.6.0
- Platform: all
- Subsystem: http, net
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 a timeout 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:
request.setTimeout calls listenSocketTimeout:
https://github.com/nodejs/node/blob/v11.6.0/lib/_http_client.js#L736
listenSocketTimeout creates a proxy (timeout event) Socket -> ClientRequest: https://github.com/nodejs/node/blob/v11.6.0/lib/_http_client.js#L673
- The proxy event is released on the response
end event:
https://github.com/nodejs/node/blob/v11.6.0/lib/_http_client.js#L682
In this case this never happens, because we set the timeout on that particular event. The correct behaviour would be to prevent calling listenSocketTimeout if msecs is 0.
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 atimeoutlistener 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: