Skip to content

Commit 2fd2dd7

Browse files
ronagTrott
authored andcommitted
http: avoid extra listener
PR-URL: nodejs#28705 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
1 parent 1721034 commit 2fd2dd7

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

lib/_http_client.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,6 @@ ClientRequest.prototype.abort = function abort() {
320320
// If we're aborting, we don't care about any more response data.
321321
if (this.res) {
322322
this.res._dump();
323-
} else {
324-
this.once('response', (res) => {
325-
res._dump();
326-
});
327323
}
328324

329325
// In the event that we don't have a socket, we will pop out of
@@ -576,12 +572,11 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
576572
// Add our listener first, so that we guarantee socket cleanup
577573
res.on('end', responseOnEnd);
578574
req.on('prefinish', requestOnPrefinish);
579-
const handled = req.emit('response', res);
580575

581576
// If the user did not listen for the 'response' event, then they
582577
// can't possibly read the data, so we ._dump() it into the void
583578
// so that the socket doesn't hang there in a paused state.
584-
if (!handled)
579+
if (req.aborted || !req.emit('response', res))
585580
res._dump();
586581

587582
if (method === 'HEAD')

0 commit comments

Comments
 (0)