diff --git a/lib/internal/socket_list.js b/lib/internal/socket_list.js index 8aa12d45d4a..dd30e945095 100644 --- a/lib/internal/socket_list.js +++ b/lib/internal/socket_list.js @@ -10,6 +10,7 @@ class SocketListSend extends EventEmitter { super(); this.key = key; this.child = child; + child.once('exit', () => this.emit('exit', this)); } _request(msg, cmd, callback) { diff --git a/lib/net.js b/lib/net.js index 9c426102d6a..2069216e0fa 100644 --- a/lib/net.js +++ b/lib/net.js @@ -1665,6 +1665,10 @@ Server.prototype.listenFD = internalUtil.deprecate(function(fd, type) { Server.prototype._setupWorker = function(socketList) { this._usingWorkers = true; this._workers.push(socketList); + socketList.once('exit', (socketList) => { + const index = this._workers.indexOf(socketList); + this._workers.splice(index, 1); + }); }; Server.prototype.ref = function() { diff --git a/test/parallel/test-child-process-fork-net2.js b/test/parallel/test-child-process-fork-net2.js index b8936854471..2686daccb28 100644 --- a/test/parallel/test-child-process-fork-net2.js +++ b/test/parallel/test-child-process-fork-net2.js @@ -156,6 +156,7 @@ if (process.argv[2] === 'child') { } process.on('exit', function() { + assert.strictEqual(server._workers.length, 0); assert.strictEqual(disconnected, count); assert.strictEqual(connected, count); });