From ed8504388e72152330b38af40cb2700f852e33f4 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Mon, 15 Jul 2019 22:25:26 +0200 Subject: [PATCH] http: avoid extra listener PR-URL: https://github.com/nodejs/node/pull/28705 Reviewed-By: James M Snell Reviewed-By: Rich Trott Reviewed-By: Trivikram Kamat Reviewed-By: Fedor Indutny --- lib/_http_client.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/_http_client.js b/lib/_http_client.js index 11e946c893b7c3..a37df35f295e2d 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -320,10 +320,6 @@ ClientRequest.prototype.abort = function abort() { // If we're aborting, we don't care about any more response data. if (this.res) { this.res._dump(); - } else { - this.once('response', (res) => { - res._dump(); - }); } // In the event that we don't have a socket, we will pop out of @@ -572,12 +568,11 @@ function parserOnIncomingClient(res, shouldKeepAlive) { // Add our listener first, so that we guarantee socket cleanup res.on('end', responseOnEnd); req.on('prefinish', requestOnPrefinish); - const handled = req.emit('response', res); // If the user did not listen for the 'response' event, then they // can't possibly read the data, so we ._dump() it into the void // so that the socket doesn't hang there in a paused state. - if (!handled) + if (req.aborted || !req.emit('response', res)) res._dump(); if (method === 'HEAD')