Skip to content

Commit c15bafd

Browse files
authored
net: only defer _final call when connecting
Fixes: #47322 PR-URL: #47385 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Robert Nagy <[email protected]>
1 parent 9398ff1 commit c15bafd

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/net.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ Socket.prototype._unrefTimer = function _unrefTimer() {
508508
// sent out to the other side.
509509
Socket.prototype._final = function(cb) {
510510
// If still connecting - defer handling `_final` until 'connect' will happen
511-
if (this.pending) {
511+
if (this.connecting) {
512512
debug('_final: not yet connected');
513513
return this.once('connect', () => this._final(cb));
514514
}

test/parallel/test-net-end-without-connect.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
'use strict';
23-
require('../common');
23+
const common = require('../common');
2424
const net = require('net');
25+
const assert = require('assert');
2526

2627
const sock = new net.Socket();
27-
sock.end(); // Should not throw.
28+
sock.end(common.mustCall(() => {
29+
assert.strictEqual(sock.writable, false);
30+
}));

0 commit comments

Comments
 (0)