Navigation Menu

Skip to content

Commit

Permalink
http: avoid extra listener
Browse files Browse the repository at this point in the history
PR-URL: #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>
  • Loading branch information
ronag authored and targos committed Jul 20, 2019
1 parent 1ce2b5e commit ed85043
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions lib/_http_client.js
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit ed85043

Please sign in to comment.