diff options
author | koichik <koichik@improvement.jp> | 2012-01-17 17:34:53 +0900 |
---|---|---|
committer | koichik <koichik@improvement.jp> | 2012-01-17 17:09:27 +0100 |
commit | 534df2f8d207877f9d09d172d4ba92406e351aa0 (patch) | |
tree | 514fef18b8136270018ca9bd1f3054f61e24ff60 /lib | |
parent | 549443a7cc600e93cc1d1d1630108e7d0a035500 (diff) | |
download | node-534df2f8d207877f9d09d172d4ba92406e351aa0.tar.gz |
tls: fix double 'error' events on HTTPS Requests
Fixes #2549.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/tls.js | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/lib/tls.js b/lib/tls.js index b77dec43d..0dd178235 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -271,7 +271,11 @@ CryptoStream.prototype._done = function() { this.pair.encrypted._doneFlag && !this.pair._doneFlag) { // If both streams are done: - this.pair.destroy(); + if (!this.pair._secureEstablished) { + this.pair.error(); + } else { + this.pair.destroy(); + } } }; @@ -720,7 +724,6 @@ SecurePair.prototype.maybeInitFinished = function() { SecurePair.prototype.destroy = function() { var self = this; - var error = this.ssl.error; if (!this._doneFlag) { this._doneFlag = true; @@ -736,21 +739,19 @@ SecurePair.prototype.destroy = function() { self.encrypted.emit('close'); self.cleartext.emit('close'); }); - - if (!this._secureEstablished) { - if (!error) { - error = new Error('socket hang up'); - error.code = 'ECONNRESET'; - } - this.emit('error', error); - } } }; SecurePair.prototype.error = function() { if (!this._secureEstablished) { + var error = this.ssl.error; + if (!error) { + error = new Error('socket hang up'); + error.code = 'ECONNRESET'; + } this.destroy(); + this.emit('error', error); } else { var err = this.ssl.error; this.ssl.error = null; |