Skip to content

Commit

Permalink
http: prevent aborted event when already completed
Browse files Browse the repository at this point in the history
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: #18756

Backport-PR-URL: #22380
PR-URL: #18999
Reviewed-By: Shingo Inoue <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
billywhizz authored and MylesBorins committed Sep 6, 2018
1 parent 02ea033 commit c4fa1f7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit c4fa1f7

Please sign in to comment.