HTTP agent: remove excess calls to removeSocket
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 (closed). Let's get rid of the extra calls to removeSocket
so we only call it once per completed request.