From a05872ff4f8751b1a992f761823bdfa6647fc806 Mon Sep 17 00:00:00 2001 From: Mariusz 'koder' Chwalba Date: Tue, 27 Sep 2016 11:15:30 +0200 Subject: [PATCH] TLS/SSL: Socket emits 'error' event on handshake failure Fixes: https://github.com/nodejs/node/issues/8803 --- lib/_tls_wrap.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index 6d07272c7c10a7..246fabcc339861 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -426,7 +426,11 @@ TLSSocket.prototype._init = function(socket, wrap) { // Destroy socket if error happened before handshake's finish if (!self._secureEstablished) { - self.destroy(self._tlsError(err)); + if (!self._controlReleased) { + self.destroy(err); + } else { + self.destroy(self._tlsError(err)); + } } else if (options.isServer && rejectUnauthorized && /peer did not return a certificate/.test(err.message)) {