From 2bc3cc4c99efe51f2667a419c34ff5f0c8408551 Mon Sep 17 00:00:00 2001 From: Pete Gonzalez Date: Sat, 1 Dec 2018 08:19:35 -0800 Subject: [PATCH] Workaround for GitHub issue #2807 (#2808) --- request.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/request.js b/request.js index 90bed4f4a..d4b13cc93 100644 --- a/request.js +++ b/request.js @@ -878,6 +878,16 @@ Request.prototype.onRequestError = function (error) { clearTimeout(self.timeoutTimer) self.timeoutTimer = null } + + // This is a workaround for a race condition caused by the way that lib/redirect.js + // calls Request.init() when processing an HTTP redirect: + // https://github.com/request/request/issues/2807 + // Somehow we end up with an ECONNRESET error from a socket that has already + // been destroyed and returned to the pool. + if (self.req && self.req.socket && self.req.socket.destroyed) { + return + } + self.emit('error', error) }