Issue #570: Disable keep-alive if no agent. #573
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an alternative fix for #570 (see my other pr #572).
The idea here is that if no agent is specified, we explicitly set keepAlive to false.
If keepAlive is true, then every time we proxy a request we will create a new connection (because there is no agent managing a pool of connections), but with keepAlive set, node.js will not kill the connection after we make a request. The connection will stay open (potentially for several minutes) eating up a file descriptor.
With keepAlive set false, node.js will close the connection for us after the request is made, cleaning up the resources immediately. Under heavy load, this will result in far more connections than in PR #572, but may or may not result in better performance overall. When heavy load clears, however, the connection count will drop back down immediately.
Note that, with or without this fix, connections are not being reused - all this does is clean up connections after we're done with them. Also not that in node v0.11.11, this option is implicitly set for us when node assigns us an agent.