Skip to content

Commit

Permalink
Fix #326
Browse files Browse the repository at this point in the history
Close socket on timeout to prevent dangling connections.
  • Loading branch information
Armen Shakhbazyan committed Mar 20, 2017
1 parent 184b48e commit 68b9c42
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/connect.js
Expand Up @@ -176,8 +176,11 @@ function connect(url, socketOptions, openCallback) {
}

if (timeout) {
sock.setTimeout(
timeout, openCallback.bind(this, new Error('connect ETIMEDOUT')));
sock.setTimeout(timeout, function() {
sock.end();
sock.destroy();
openCallback(new Error('connect ETIMEDOUT'));
});
}

sock.once('error', function(err) {
Expand Down

0 comments on commit 68b9c42

Please sign in to comment.