Skip to content

Commit c67b545

Browse files
committed
http: don't emit 'finish' after 'error'
1 parent 4fedb70 commit c67b545

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

lib/_http_outgoing.js

+1
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,7 @@ OutgoingMessage.prototype.addTrailers = function addTrailers(headers) {
745745
};
746746

747747
function onFinish(outmsg) {
748+
if (outmsg && outmsg.socket && outmsg.socket._hadError) return;
748749
outmsg.emit('finish');
749750
}
750751

test/parallel/test-tls-set-secure-context.js

+4
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ function makeRequest(port, id) {
8282
headers: { id }
8383
};
8484

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

@@ -95,7 +96,10 @@ function makeRequest(port, id) {
9596
resolve(response);
9697
}));
9798
}).on('error', (err) => {
99+
errored = true;
98100
reject(err);
101+
}).on('finish', () => {
102+
assert.strictEqual(errored, false);
99103
});
100104
});
101105
}

0 commit comments

Comments
 (0)