Browse Source

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
v0.10.13-release
Timothy J Fontaine 12 years ago
committed by isaacs
parent
commit
91698f77e5
  1. 5
      lib/tls.js

5
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 // Wait for both `finish` and `end` events to ensure that all data that
// was written on this side was read from the other side. // was written on this side was read from the other side.
var self = this; var self = this;
var waiting = 2; var waiting = 1;
function finish() { function finish() {
if (--waiting === 0) self.destroy(); if (--waiting === 0) self.destroy();
} }
this._opposite.once('end', finish); this._opposite.once('end', finish);
if (!this._finished) {
this.once('finish', finish); this.once('finish', finish);
++waiting;
}
} }
}; };

Loading…
Cancel
Save