Skip to content

Commit

Permalink
http: don't emit 'finish' after 'error'
Browse files Browse the repository at this point in the history
PR-URL: #32276
Refs: #28710
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
ronag authored and MylesBorins committed Mar 24, 2020
1 parent 05fd160 commit ef32069
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ OutgoingMessage.prototype.addTrailers = function addTrailers(headers) {
};

function onFinish(outmsg) {
if (outmsg && outmsg.socket && outmsg.socket._hadError) return;
outmsg.emit('finish');
}

Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-tls-set-secure-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function makeRequest(port, id) {
headers: { id }
};

let errored = false;
https.get(`https://localhost:${port}`, options, (res) => {
let response = '';

Expand All @@ -95,7 +96,10 @@ function makeRequest(port, id) {
resolve(response);
}));
}).on('error', (err) => {
errored = true;
reject(err);
}).on('finish', () => {
assert.strictEqual(errored, false);
});
});
}

0 comments on commit ef32069

Please sign in to comment.