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 authored and GitHub committed 2023-05-08 07:47:48 +00:00
1 parent 9398ff1dea
commit c15bafdaf4
2 files changed
+6 -3

No files matched your search

+1 -1
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));
}
@@ -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);
}));