From a9270dcbeba4316b1e179b77ecb6c46af5aa8c20 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Sun, 15 Mar 2020 00:55:03 +0100 Subject: [PATCH] http: don't emit 'finish' after 'error' PR-URL: https://github.com/nodejs/node/pull/32276 Refs: https://github.com/nodejs/node/issues/28710 Reviewed-By: James M Snell Reviewed-By: Trivikram Kamat --- lib/_http_outgoing.js | 1 + test/parallel/test-tls-set-secure-context.js | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index a7bd6af60073a7..a22621ea4319dc 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -745,6 +745,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); }); }); }