diff --git a/lib/net.js b/lib/net.js index e29b62c8127648..946b1550fa5267 100644 --- a/lib/net.js +++ b/lib/net.js @@ -507,7 +507,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)); } diff --git a/test/parallel/test-net-end-without-connect.js b/test/parallel/test-net-end-without-connect.js index 98cf49768a2a26..45d0b5477ed227 100644 --- a/test/parallel/test-net-end-without-connect.js +++ b/test/parallel/test-net-end-without-connect.js @@ -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); +}));