child_process: fix memory leak in .fork()
Entries in the `net.Server#_workers` array that is used to track handles sent from the master to workers were not deleted when a worker exited, resulting in a slow but inexorable memory leak. PR-URL: https://github.com/nodejs/node/pull/15679 Fixes: https://github.com/nodejs/node/issues/15651 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
3e4f34cdb9
commit
2e59ec0c2d
@ -10,6 +10,7 @@ class SocketListSend extends EventEmitter {
|
|||||||
super();
|
super();
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.child = child;
|
this.child = child;
|
||||||
|
child.once('exit', () => this.emit('exit', this));
|
||||||
}
|
}
|
||||||
|
|
||||||
_request(msg, cmd, callback) {
|
_request(msg, cmd, callback) {
|
||||||
|
@ -1665,6 +1665,10 @@ Server.prototype.listenFD = internalUtil.deprecate(function(fd, type) {
|
|||||||
Server.prototype._setupWorker = function(socketList) {
|
Server.prototype._setupWorker = function(socketList) {
|
||||||
this._usingWorkers = true;
|
this._usingWorkers = true;
|
||||||
this._workers.push(socketList);
|
this._workers.push(socketList);
|
||||||
|
socketList.once('exit', (socketList) => {
|
||||||
|
const index = this._workers.indexOf(socketList);
|
||||||
|
this._workers.splice(index, 1);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Server.prototype.ref = function() {
|
Server.prototype.ref = function() {
|
||||||
|
@ -156,6 +156,7 @@ if (process.argv[2] === 'child') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function() {
|
||||||
|
assert.strictEqual(server._workers.length, 0);
|
||||||
assert.strictEqual(disconnected, count);
|
assert.strictEqual(disconnected, count);
|
||||||
assert.strictEqual(connected, count);
|
assert.strictEqual(connected, count);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user