diff options
author | isaacs <i@izs.me> | 2013-03-29 00:11:04 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-03-29 00:11:04 +0400 |
commit | 97c70a6628d284a95e3b17a02f2d78661c992263 (patch) | |
tree | 90433dee218e8434d59bcb776d2703e98b693e79 /lib/tls.js | |
parent | 120e5a24df76deb5019abec9744ace94f0f3746a (diff) | |
parent | 708e8589ea76548f61ccbf8c064fd65a34429b1f (diff) |
Merge remote-tracking branch 'ry/v0.10'
Conflicts:
src/node.cc
src/node_version.h
Diffstat (limited to 'lib/tls.js')
-rw-r--r-- | lib/tls.js | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/lib/tls.js b/lib/tls.js index 334f4116ba1..f0cdaac9678 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -335,7 +335,10 @@ CryptoStream.prototype._write = function write(data, encoding, cb) { written = this.pair.ssl.encIn(data, 0, data.length); } - var self = this; + // Handle and report errors + if (this.pair.ssl && this.pair.ssl.error) { + return cb(this.pair.error(true)); + } // Force SSL_read call to cycle some states/data inside OpenSSL this.pair.cleartext.read(0); @@ -345,11 +348,6 @@ CryptoStream.prototype._write = function write(data, encoding, cb) { this.pair.encrypted.read(0); } - // Handle and report errors - if (this.pair.ssl && this.pair.ssl.error) { - return cb(this.pair.error()); - } - // Get NPN and Server name when ready this.pair.maybeInitFinished(); @@ -919,24 +917,28 @@ SecurePair.prototype.destroy = function() { }; -SecurePair.prototype.error = function() { +SecurePair.prototype.error = function(returnOnly) { var err = this.ssl.error; 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(); - this.emit('error', err); + if (!returnOnly) this.emit('error', err); } else if (this._isServer && this._rejectUnauthorized && /peer did not return a certificate/.test(err.message)) { // Not really an error. this.destroy(); } else { - this.cleartext.emit('error', err); + if (!returnOnly) this.cleartext.emit('error', err); } return err; }; |