diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 4e08ebece8dd12..49f6e57fb1c6fd 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -727,6 +727,7 @@ OutgoingMessage.prototype.addTrailers = function addTrailers(headers) { }; function onFinish(outmsg) { + if (outmsg && outmsg.socket && outmsg.socket._hadError) return; outmsg.emit('finish'); } diff --git a/test/parallel/test-tls-set-secure-context.js b/test/parallel/test-tls-set-secure-context.js index f8857701c68b3c..f72daff6ef14fb 100644 --- a/test/parallel/test-tls-set-secure-context.js +++ b/test/parallel/test-tls-set-secure-context.js @@ -82,6 +82,7 @@ function makeRequest(port, id) { headers: { id } }; + let errored = false; https.get(`https://localhost:${port}`, options, (res) => { let response = ''; @@ -95,7 +96,10 @@ function makeRequest(port, id) { resolve(response); })); }).on('error', (err) => { + errored = true; reject(err); + }).on('finish', () => { + assert.strictEqual(errored, false); }); }); }