Comparing version 3.1.1 to 3.1.2
36
index.js
@@ -21,23 +21,12 @@ 'use strict'; | ||
// Clear the connection timeout timer once a socket is assigned to the | ||
// request and is connected. Abort the request if there is no activity | ||
// on the socket for more than `time` milliseconds. | ||
// request and is connected. | ||
req.on('socket', function assign(socket) { | ||
// Socket may come from Agent pool and may be already connected | ||
// .connecting is for node 6.x and ._connecting is fallback for older releases | ||
if (!(socket.connecting || socket._connecting)) { | ||
if (socket._timedOutHandlerSet) { | ||
clear(); | ||
return; | ||
} | ||
socket.on('connect', function connect() { | ||
clear(); | ||
if (delays.socket !== undefined) { | ||
socket.setTimeout(delays.socket, function socketTimeoutHandler() { | ||
req.abort(); | ||
var e = new Error('Socket timed out on request' + host); | ||
e.code = 'ESOCKETTIMEDOUT'; | ||
req.emit('error', e); | ||
}); | ||
} | ||
}); | ||
socket._timedOutHandlerSet = true; | ||
socket.on('connect', connect); | ||
}); | ||
@@ -52,3 +41,18 @@ | ||
function connect() { | ||
clear(); | ||
if (delays.socket !== undefined) { | ||
// Abort the request if there is no activity on the socket for more | ||
// than `delays.socket` milliseconds. | ||
this.setTimeout(delays.socket, function socketTimeoutHandler() { | ||
req.abort(); | ||
var e = new Error('Socket timed out on request' + host); | ||
e.code = 'ESOCKETTIMEDOUT'; | ||
req.emit('error', e); | ||
}); | ||
} | ||
} | ||
return req.on('error', clear); | ||
}; |
{ | ||
"name": "timed-out", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"description": "Emit `ETIMEDOUT` or `ESOCKETTIMEDOUT` when ClientRequest is hanged", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
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
47
4095