diff options
author | Timothy J Fontaine <tjfontaine@gmail.com> | 2013-06-23 22:33:13 +0000 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-07-09 10:55:10 -0700 |
commit | 91698f77e527d6559285031eb91974119c80715e (patch) | |
tree | bce41de511da4519b300691d3a5d3c9110ff9c8f | |
parent | ed5324687ef6cc8bebcbe418301c3f06346f20ae (diff) | |
download | node-91698f77e527d6559285031eb91974119c80715e.tar.gz |
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
-rw-r--r-- | lib/tls.js | 7 |
1 files 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; + } } }; |