Skip to content

Commit 6e33069

Browse files
committed
net: do not duplicate connect and finish listners on destroySoon
1 parent fb34515 commit 6e33069

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/net.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,9 @@ Socket.prototype._unrefTimer = function _unrefTimer() {
529529
// sent out to the other side.
530530
Socket.prototype._final = function(cb) {
531531
// If still connecting - defer handling `_final` until 'connect' will happen
532-
if (this.connecting) {
532+
if (this.connecting && !this._finalizingOnConnect) {
533533
debug('_final: not yet connected');
534+
this._finalizingOnConnect = true;
534535
return this.once('connect', () => this._final(cb));
535536
}
536537

@@ -800,8 +801,10 @@ Socket.prototype.destroySoon = function() {
800801

801802
if (this.writableFinished)
802803
this.destroy();
803-
else
804+
else if (!this._destroyingOnFinish) {
805+
this._destroyingOnFinish = true;
804806
this.once('finish', this.destroy);
807+
}
805808
};
806809

807810

0 commit comments

Comments
 (0)