Skip to content

Commit 91698f7

Browse files
tjfontaineisaacs
authored andcommitted
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
1 parent ed53246 commit 91698f7

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

lib/tls.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,12 +645,15 @@ CryptoStream.prototype.destroySoon = function(err) {
645645
// Wait for both `finish` and `end` events to ensure that all data that
646646
// was written on this side was read from the other side.
647647
var self = this;
648-
var waiting = 2;
648+
var waiting = 1;
649649
function finish() {
650650
if (--waiting === 0) self.destroy();
651651
}
652652
this._opposite.once('end', finish);
653-
this.once('finish', finish);
653+
if (!this._finished) {
654+
this.once('finish', finish);
655+
++waiting;
656+
}
654657
}
655658
};
656659

0 commit comments

Comments
 (0)