Add free socket timeout: avoid long time inactivity socket leak in the free-sockets queue.
Add active socket timeout: avoid long time inactivity socket leak in the active-sockets queue.
TTL for active socket.
Node.js version required
Support Node.js >= 8.0.0
Install
$ npm install agentkeepalive --save
new Agent([options])
options {Object} Set of configurable options to set on the agent.
Can have the following fields:
keepAlive {Boolean} Keep sockets around in a pool to be used by
other requests in the future. Default = true.
keepAliveMsecs {Number} When using the keepAlive option, specifies the initial delay
for TCP Keep-Alive packets. Ignored when the keepAlive option is false or undefined. Defaults to 1000.
Default = 1000. Only relevant if keepAlive is set to true.
freeSocketTimeout: {Number} Sets the free socket to timeout
after freeSocketTimeout milliseconds of inactivity on the free socket.
The default server-side timeout is 5000 milliseconds, to avoid ECONNRESET exceptions, we set the default value to 4000 milliseconds.
Only relevant if keepAlive is set to true.
timeout: {Number} Sets the working socket to timeout
after timeout milliseconds of inactivity on the working socket.
Default is freeSocketTimeout * 2 so long as that value is greater than or equal to 8 seconds, otherwise the default is 8 seconds.
maxSockets {Number} Maximum number of sockets to allow per
host. Default = Infinity.
{Number} Maximum number of sockets (per host) to leave open
in a free state. Only relevant if is set to .
Default = .
This agent implements the req.reusedSocket to determine whether a request is send through a reused socket.
When server closes connection at unfortunate time (keep-alive race), the http client will throw a ECONNRESET error. Under this circumstance, req.reusedSocket is useful when we want to retry the request automatically.
socketActiveTTL {Number} Sets the socket active time to live, even if it's in use.
If not set, the behaviour keeps the same (the socket will be released only when free)
Default = null.