diff --git a/lib/tls.js b/lib/tls.js index af15867aa48..0907b290f32 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -646,15 +646,16 @@ CryptoStream.prototype.destroySoon = function(err) { // was written on this side was read from the other side. var self = this; var waiting = 1; - function finish() { - if (--waiting === 0) self.destroy(); - } this._opposite.once('end', finish); if (!this._finished) { this.once('finish', finish); ++waiting; } } + + function finish() { + if (--waiting === 0) self.destroy(); + } };