From c4fa1f72a2879fc7307529139678acf70ad30d5e Mon Sep 17 00:00:00 2001 From: Andrew Johnston Date: Sat, 17 Feb 2018 19:03:12 +0100 Subject: [PATCH] http: prevent aborted event when already completed When socket is closed on a response for a request that is being piped to a stream there is a condition where aborted event will be fired to http client when socket is closing and the incomingMessage stream is still set to readable. We need a check for request being complete and to only raise the 'aborted' event on the http client if we have not yet completed reading the response from the server. Fixes: https://github.com/nodejs/node/issues/18756 Backport-PR-URL: https://github.com/nodejs/node/pull/22380 PR-URL: https://github.com/nodejs/node/pull/18999 Reviewed-By: Shingo Inoue Reviewed-By: Matteo Collina Reviewed-By: James M Snell --- lib/_http_client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/_http_client.js b/lib/_http_client.js index 135d31acaaec2d..460521c8ded85c 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -350,7 +350,7 @@ function socketCloseListener() { req.emit('close'); if (req.res && req.res.readable) { // Socket closed before we emitted 'end' below. - req.res.emit('aborted'); + if (!req.res.complete) req.res.emit('aborted'); var res = req.res; res.on('end', function() { res.emit('close');