From 91698f77e527d6559285031eb91974119c80715e Mon Sep 17 00:00:00 2001 From: Timothy J Fontaine Date: Sun, 23 Jun 2013 22:33:13 +0000 Subject: tls: only wait for finish if we haven't seen it A pooled https agent may get a Connection: close, but never finish destroying the socket as the prior request had already emitted finish likely from a pipe. Since the socket is not marked as destroyed it may get reused by the agent pool and result in an ECONNRESET. re: #5712 #5739 --- lib/tls.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/tls.js b/lib/tls.js index 4d222f352..af15867aa 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; + } } }; -- cgit v1.2.1