From 93813e61e5f3e93ae5132db76f8a32ad3fee0e1a Mon Sep 17 00:00:00 2001 From: someone--else Date: Wed, 18 Nov 2015 02:46:13 +0300 Subject: [PATCH] agent: pass client socket to request on error so any errors encountered while connecting to the proxy are handled properly --- lib/Agents.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Agents.js b/lib/Agents.js index 6d79453..9d70681 100644 --- a/lib/Agents.js +++ b/lib/Agents.js @@ -194,6 +194,8 @@ Agent.prototype.addRequest = function(req, options) { var client = this.createSocket(req, options); client.once('connect', function(s) { req.onSocket(s._tlssock || s); + }).on('error', function(e) { + req.onSocket(client._sock); }); } else { debug('wait for socket'); @@ -292,6 +294,8 @@ Agent.prototype.removeSocket = function(s, options) { var client = this.createSocket(req, options); client.once('connect', function(s) { (s._tlssock || s).emit('free'); + }).on('error', function(e) { + req.onSocket(client._sock); }); } };