Skip to content

Commit

Permalink
http: don't emit 'finish' after 'error'
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Mar 14, 2020
1 parent 4fedb70 commit c67b545
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 @@ -745,6 +745,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 c67b545

Please sign in to comment.