-
Notifications
You must be signed in to change notification settings - Fork 30k
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.globalAgent.maxSockets is not always respected #4050
Comments
It doesn't look like request.abort() frees the sockets in the agent. I tried keepAlive + maxFreeSockets but that didn't work either (all requests were sent at once). Here's how I was able to get your example to work:
EDIT: socket.destroy() also works. I'm looking at request.abort's code and in theory it should call the same method (calls this.socket.destroy). So no idea why this is happening. |
socket.destroy() triggers a 'close' event from the socket which triggers the onClose handler of HTTPAgent which calls self.removeSocket(). So by calling self.removeSocket() prior to socket.destroy() we end up with two calls to self.removeSocket(). If there are pending requests, removeSocket ends up creating a new socket. So if there are pending requests, each time a request completes, we tear down one socket and create two more. So the total number of sockets grows exponentially and without regard for any maxSockets settings. This was noticed in nodejs#4050. Let's get rid of the extra calls to removeSocket so we only call it once per completed request.
socket.destroy() triggers a 'close' event from the socket which triggers the onClose handler of HTTPAgent which calls self.removeSocket(). So by calling self.removeSocket() prior to socket.destroy() we end up with two calls to self.removeSocket(). If there are pending requests, removeSocket ends up creating a new socket. So if there are pending requests, each time a request completes, we tear down one socket and create two more. So the total number of sockets grows exponentially and without regard for any maxSockets settings. This was noticed in #4050. Let's get rid of the extra calls to removeSocket so we only call it once per completed request. PR-URL: #4172 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Fedor Indutny <fedor@indutny.com>
This should be fixed by 6e11e22. Can you verify @cyrus-and? |
@mscdex everything is working as expected now, thanks. |
socket.destroy() triggers a 'close' event from the socket which triggers the onClose handler of HTTPAgent which calls self.removeSocket(). So by calling self.removeSocket() prior to socket.destroy() we end up with two calls to self.removeSocket(). If there are pending requests, removeSocket ends up creating a new socket. So if there are pending requests, each time a request completes, we tear down one socket and create two more. So the total number of sockets grows exponentially and without regard for any maxSockets settings. This was noticed in nodejs#4050. Let's get rid of the extra calls to removeSocket so we only call it once per completed request. PR-URL: nodejs#4172 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Fedor Indutny <fedor@indutny.com>
socket.destroy() triggers a 'close' event from the socket which triggers the onClose handler of HTTPAgent which calls self.removeSocket(). So by calling self.removeSocket() prior to socket.destroy() we end up with two calls to self.removeSocket(). If there are pending requests, removeSocket ends up creating a new socket. So if there are pending requests, each time a request completes, we tear down one socket and create two more. So the total number of sockets grows exponentially and without regard for any maxSockets settings. This was noticed in nodejs#4050. Let's get rid of the extra calls to removeSocket so we only call it once per completed request. PR-URL: nodejs#4172 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Fedor Indutny <fedor@indutny.com>
socket.destroy() triggers a 'close' event from the socket which triggers the onClose handler of HTTPAgent which calls self.removeSocket(). So by calling self.removeSocket() prior to socket.destroy() we end up with two calls to self.removeSocket(). If there are pending requests, removeSocket ends up creating a new socket. So if there are pending requests, each time a request completes, we tear down one socket and create two more. So the total number of sockets grows exponentially and without regard for any maxSockets settings. This was noticed in #4050. Let's get rid of the extra calls to removeSocket so we only call it once per completed request. PR-URL: #4172 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Fedor Indutny <fedor@indutny.com>
socket.destroy() triggers a 'close' event from the socket which triggers the onClose handler of HTTPAgent which calls self.removeSocket(). So by calling self.removeSocket() prior to socket.destroy() we end up with two calls to self.removeSocket(). If there are pending requests, removeSocket ends up creating a new socket. So if there are pending requests, each time a request completes, we tear down one socket and create two more. So the total number of sockets grows exponentially and without regard for any maxSockets settings. This was noticed in #4050. Let's get rid of the extra calls to removeSocket so we only call it once per completed request. PR-URL: #4172 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Fedor Indutny <fedor@indutny.com>
socket.destroy() triggers a 'close' event from the socket which triggers the onClose handler of HTTPAgent which calls self.removeSocket(). So by calling self.removeSocket() prior to socket.destroy() we end up with two calls to self.removeSocket(). If there are pending requests, removeSocket ends up creating a new socket. So if there are pending requests, each time a request completes, we tear down one socket and create two more. So the total number of sockets grows exponentially and without regard for any maxSockets settings. This was noticed in nodejs#4050. Let's get rid of the extra calls to removeSocket so we only call it once per completed request. PR-URL: nodejs#4172 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Fedor Indutny <fedor@indutny.com>
Aborting a pending request (whose response is not read yet) causes
http.globalAgent.maxSockets
to not being respected for future requests.Specifically:
'response'
listener registered for the requests.I can reproduce the issue with the following:
client.js
:server.js
:Run
server.js
thenclient.js
; the output of the former is:I was expecting groups of three requests each, instead of: 100 = 3 + 6 + 12 + 24 + 48 + 7.
The output of
client.js
reflects the one ofserver.js
.This happen at least with
v4.1.1
andv5.1.0
.I apologize if the above is the intended behavior and I'm just misunderstanding
request.abort()
andagent.maxSockets
.The text was updated successfully, but these errors were encountered: