diff --git a/lib/tls.js b/lib/tls.js index 4d222f3521..af15867aa4 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -645,12 +645,15 @@ CryptoStream.prototype.destroySoon = function(err) { // Wait for both `finish` and `end` events to ensure that all data that // was written on this side was read from the other side. var self = this; - var waiting = 2; + var waiting = 1; function finish() { if (--waiting === 0) self.destroy(); } this._opposite.once('end', finish); - this.once('finish', finish); + if (!this._finished) { + this.once('finish', finish); + ++waiting; + } } };