Skip to content

Commit ed85043

Browse files
ronagtargos
authored andcommitted
http: avoid extra listener
PR-URL: #28705 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Fedor Indutny <[email protected]>
1 parent 1ce2b5e commit ed85043

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
@@ -572,12 +568,11 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
572568
// Add our listener first, so that we guarantee socket cleanup
573569
res.on('end', responseOnEnd);
574570
req.on('prefinish', requestOnPrefinish);
575-
const handled = req.emit('response', res);
576571

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

583578
if (method === 'HEAD')

0 commit comments

Comments
 (0)