diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index d6f1480040bd3b..9049a830f805e4 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -250,9 +250,11 @@ function onocspresponse(resp) { function onerror(err) { const owner = this[owner_symbol]; - if (owner._writableState.errorEmitted) + if (owner._hadError) return; + owner._hadError = true; + // Destroy socket if error happened before handshake's finish if (!owner._secureEstablished) { // When handshake fails control is not yet released, @@ -267,8 +269,6 @@ function onerror(err) { // Throw error owner._emitTLSError(err); } - - owner._writableState.errorEmitted = true; } function initRead(tls, wrapped) {