diff --git a/lib/request.js b/lib/request.js index 567fc8d..976774d 100644 --- a/lib/request.js +++ b/lib/request.js @@ -92,7 +92,16 @@ function regRequest (uri, params, cb_) { } function makeRequest (uri, params, cb_) { - var cb = once(cb_) + var socket + var cb = once(function (er, parsed, resp, data) { + if (socket) { + // The socket might be returned to a pool for re-use, so don’t keep + // the 'error' from here attached. + socket.removeListener('error', cb) + } + + return cb_(er, parsed, resp, data) + }) var parsed = url.parse(uri) var headers = {} @@ -150,7 +159,8 @@ function makeRequest (uri, params, cb_) { req.on('error', cb) req.on('socket', function (s) { - s.on('error', cb) + socket = s + socket.on('error', cb) }) if (params.body && (params.body instanceof Stream)) {