diff --git a/lib/net.js b/lib/net.js index f52222ec58..71195750a3 100644 --- a/lib/net.js +++ b/lib/net.js @@ -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)); } diff --git a/test/parallel/test-net-end-without-connect.js b/test/parallel/test-net-end-without-connect.js index 98cf49768a..45d0b5477e 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); +}));