diff --git a/lib/internal/socket_list.js b/lib/internal/socket_list.js index 961289efebc3c9..0d36b06cd7ccdc 100644 --- a/lib/internal/socket_list.js +++ b/lib/internal/socket_list.js @@ -8,6 +8,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 753bc42e6d2629..70d4841d5e7b05 100644 --- a/lib/net.js +++ b/lib/net.js @@ -1664,6 +1664,10 @@ Server.prototype.listenFD = internalUtil.deprecate(function(fd, type) { Server.prototype._setupSlave = function(socketList) { this._usingSlaves = true; this._slaves.push(socketList); + socketList.once('exit', (socketList) => { + const index = this._slaves.indexOf(socketList); + this._slaves.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 b893685447191f..995d2d4c6c4ccb 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._slaves.length, 0); assert.strictEqual(disconnected, count); assert.strictEqual(connected, count); });