From 4580be088238853ac84d600a56a05159190c1729 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Thu, 28 Mar 2013 20:55:51 +0400 Subject: [PATCH] tls: handle SSL_ERROR_ZERO_RETURN see #5004 --- lib/tls.js | 10 +++++++--- src/node_crypto.cc | 5 +++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/tls.js b/lib/tls.js index 3ec126e3c4..5385912173 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -922,9 +922,13 @@ SecurePair.prototype.error = function(returnOnly) { this.ssl.error = null; if (!this._secureEstablished) { - if (!err) { - err = new Error('socket hang up'); - err.code = 'ECONNRESET'; + // Emit ECONNRESET instead of zero return + if (!err || err.message === 'ZERO_RETURN') { + var connReset = new Error('socket hang up'); + connReset.code = 'ECONNRESET'; + connReset.sslError = err && err.message; + + err = connReset; } this.destroy(); if (!returnOnly) this.emit('error', err); diff --git a/src/node_crypto.cc b/src/node_crypto.cc index c53d2ce7ac..ec2dbe4916 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -927,6 +927,11 @@ int Connection::HandleSSLError(const char* func, int rv, ZeroStatus zs) { DEBUG_PRINT("[%p] SSL: %s want read\n", ssl_, func); return 0; + } else if (err == SSL_ERROR_ZERO_RETURN) { + handle_->Set(String::New("error"), + Exception::Error(String::New("ZERO_RETURN"))); + return rv; + } else { HandleScope scope; BUF_MEM* mem;