Skip to content

Commit

Permalink
net: only defer _final call when connecting
Browse files Browse the repository at this point in the history
Fixes: #47322
PR-URL: #47385
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
  • Loading branch information
jazelly committed May 8, 2023
1 parent 9398ff1 commit c15bafd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
7 changes: 5 additions & 2 deletions test/parallel/test-net-end-without-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}));

0 comments on commit c15bafd

Please sign in to comment.