Skip to content

Commit 40ef455

Browse files
committed
revert changes in _final
1 parent a63fb37 commit 40ef455

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

lib/net.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -531,14 +531,7 @@ Socket.prototype._final = function(cb) {
531531
// If still connecting - defer handling `_final` until 'connect' will happen
532532
if (this.connecting) {
533533
debug('_final: not yet connected');
534-
if (!this._finalizingOnConnect) {
535-
this._finalizingOnConnect = true;
536-
this.once('connect', () => {
537-
this._final(cb);
538-
this._finalizingOnConnect = false;
539-
});
540-
}
541-
return;
534+
return this.once('connect', () => this._final(cb));
542535
}
543536

544537
if (!this._handle)
@@ -810,8 +803,8 @@ Socket.prototype.destroySoon = function() {
810803
else if (!this._destroyingOnFinish) {
811804
this._destroyingOnFinish = true;
812805
this.once('finish', () => {
813-
this.destroy();
814806
this._destroyingOnFinish = false;
807+
this.destroy();
815808
});
816809
}
817810
};

test/parallel/test-net-socket-not-duplicates-destroy-soon-listeners.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,13 @@ require('../common');
33
const { addresses } = require('../common/internet');
44

55
const assert = require('assert');
6-
const net = require('net');
6+
const { Socket } = require('net');
77

8-
const socket = new net.Socket();
8+
const socket = new Socket();
99
socket.on('error', () => {
1010
// noop
1111
});
12-
const connectOptions = { host: addresses.INVALID_HOST, port: 1234 };
13-
14-
socket.connect(connectOptions);
15-
socket.destroySoon(); // Adds "connect" and "finish" event listeners when socket has "writable" state
16-
socket.destroy(); // Makes imideditly socket again "writable"
17-
18-
socket.connect(connectOptions);
19-
socket.destroySoon(); // Should not duplicate "connect" and "finish" event listeners
20-
12+
socket.connect({ host: addresses.INVALID_HOST, port: 1234 });
13+
socket.destroySoon();
14+
socket.destroySoon();
2115
assert.strictEqual(socket.listeners('finish').length, 1);
22-
assert.strictEqual(socket.listeners('connect').length, 1);

0 commit comments

Comments
 (0)