agentkeepalive
Advanced tools
Comparing version 3.1.0 to 3.2.0
3.2.0 / 2017-06-10 | ||
================== | ||
* feat: add expiring active sockets | ||
* test: add node 8 (#49) | ||
3.1.0 / 2017-02-20 | ||
@@ -3,0 +9,0 @@ ================== |
@@ -71,2 +71,4 @@ // Copyright Joyent, Inc. and other Node contributors. | ||
self.timeout = self.options.timeout || 0; | ||
// the socket active time to live, even if it's in use | ||
this.socketActiveTTL = this.options.socketActiveTTL || null; | ||
// [patch end] | ||
@@ -167,2 +169,16 @@ | ||
// [patch start] | ||
function handleSocketCreation(req) { | ||
return function(err, newSocket) { | ||
if (err) { | ||
process.nextTick(function() { | ||
req.emit('error', err); | ||
}); | ||
return; | ||
} | ||
req.onSocket(newSocket); | ||
} | ||
} | ||
// [patch end] | ||
Agent.prototype.addRequest = function addRequest(req, options) { | ||
@@ -207,2 +223,8 @@ // Legacy API: addRequest(req, host, port, localAddress) | ||
socket.setTimeout(this.timeout); | ||
if (this.socketActiveTTL && Date.now() - socket.createdTime > this.socketActiveTTL) { | ||
debug(`socket ${socket.createdTime} expired`); | ||
socket.destroy(); | ||
return this.createSocket(req, options, handleSocketCreation(req)); | ||
} | ||
// [patch end] | ||
@@ -220,11 +242,5 @@ | ||
// If we are under maxSockets create a new one. | ||
this.createSocket(req, options, function(err, newSocket) { | ||
if (err) { | ||
process.nextTick(function() { | ||
req.emit('error', err); | ||
}); | ||
return; | ||
} | ||
req.onSocket(newSocket); | ||
}); | ||
// [patch start] | ||
this.createSocket(req, options, handleSocketCreation(req)); | ||
// [patch end] | ||
} else { | ||
@@ -260,4 +276,7 @@ debug('wait for socket'); | ||
const newSocket = self.createConnection(options, oncreate); | ||
if (newSocket) | ||
oncreate(null, newSocket); | ||
// [patch start] | ||
if (newSocket) { | ||
oncreate(null, Object.assign(newSocket, { createdTime: Date.now() })); | ||
} | ||
// [patch end] | ||
function oncreate(err, s) { | ||
@@ -264,0 +283,0 @@ if (called) |
{ | ||
"name": "agentkeepalive", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "Missing keepalive http.Agent", | ||
@@ -16,3 +16,4 @@ "main": "index.js", | ||
"ci": "npm run lint && npm run cov", | ||
"lint": "eslint lib test index.js" | ||
"lint": "eslint lib test index.js", | ||
"autod": "autod" | ||
}, | ||
@@ -34,10 +35,11 @@ "repository": { | ||
"dependencies": { | ||
"humanize-ms": "^1.2.0" | ||
"humanize-ms": "^1.2.1" | ||
}, | ||
"devDependencies": { | ||
"egg-bin": "^1.9.1", | ||
"egg-ci": "^1.1.0", | ||
"eslint": "^3.12.2", | ||
"eslint-config-egg": "^3.2.0", | ||
"pedding": "1" | ||
"autod": "^2.8.0", | ||
"egg-bin": "^1.10.3", | ||
"egg-ci": "^1.7.0", | ||
"eslint": "^3.19.0", | ||
"eslint-config-egg": "^4.2.0", | ||
"pedding": "^1.1.0" | ||
}, | ||
@@ -48,3 +50,3 @@ "engines": { | ||
"ci": { | ||
"version": "4.3.2, 4, 6, 7" | ||
"version": "4.3.2, 4, 6, 7, 8" | ||
}, | ||
@@ -51,0 +53,0 @@ "author": "fengmk2 <fengmk2@gmail.com> (https://fengmk2.com)", |
@@ -62,2 +62,5 @@ # agentkeepalive | ||
Default = `256`. | ||
* `socketActiveTTL` {Number} Sets the socket active time to live, even if it's in use. | ||
If not setted the behaviour continues the same (the socket will be released only when free) | ||
Default = `null`. | ||
@@ -64,0 +67,0 @@ ## Usage |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28483
479
241
6
Updatedhumanize-ms@^1.2.1