From b962ff35ddcd7b2120dd1804dcd3109d924c513a Mon Sep 17 00:00:00 2001 From: koichik Date: Tue, 27 Dec 2011 17:33:23 +0900 Subject: [PATCH] tls: fix test-https-client-reject fails Fixes #2417. --- lib/tls.js | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/lib/tls.js b/lib/tls.js index 47f2e0c54bb..5a3afd9d38e 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -719,31 +719,33 @@ SecurePair.prototype.maybeInitFinished = function() { SecurePair.prototype.destroy = function() { + if (this._doneFlag) { + return; + } + var self = this; var error = this.ssl.error; - if (!this._doneFlag) { - this._doneFlag = true; - this.ssl.error = null; - this.ssl.close(); - this.ssl = null; + this._doneFlag = true; + this.ssl.error = null; + this.ssl.close(); + this.ssl = null; - self.encrypted.writable = self.encrypted.readable = false; - self.cleartext.writable = self.cleartext.readable = false; + self.encrypted.writable = self.encrypted.readable = false; + self.cleartext.writable = self.cleartext.readable = false; - process.nextTick(function() { - self.cleartext.emit('end'); - self.encrypted.emit('close'); - self.cleartext.emit('close'); - }); + process.nextTick(function() { + self.cleartext.emit('end'); + 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); + if (!this._secureEstablished) { + if (!error) { + error = new Error('socket hang up'); + error.code = 'ECONNRESET'; } + this.emit('error', error); } };