net: only defer _final call when connecting

Fixes: https://github.com/nodejs/node/issues/47322
PR-URL: https://github.com/nodejs/node/pull/47385
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
This commit is contained in:
Jason Zhang
2023-05-08 17:17:48 +09:30
committed by GitHub
parent 9398ff1dea
commit c15bafdaf4
2 changed files with 6 additions and 3 deletions

View File

@@ -508,7 +508,7 @@ Socket.prototype._unrefTimer = function _unrefTimer() {
// sent out to the other side.
Socket.prototype._final = function(cb) {
// If still connecting - defer handling `_final` until 'connect' will happen
if (this.pending) {
if (this.connecting) {
debug('_final: not yet connected');
return this.once('connect', () => this._final(cb));
}

View File

@@ -20,8 +20,11 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
require('../common');
const common = require('../common');
const net = require('net');
const assert = require('assert');
const sock = new net.Socket();
sock.end(); // Should not throw.
sock.end(common.mustCall(() => {
assert.strictEqual(sock.writable, false);
}));