Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9bea207

Browse filesBrowse files
bnoordhuisgibfahn
authored andcommitted
child_process: fix memory leak in .fork()
Entries in the `net.Server#_slaves` 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: #15679 Backport-PR-URL: #16586 Fixes: #15651 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent ad69207 commit 9bea207
Copy full SHA for 9bea207

File tree

Expand file treeCollapse file tree

3 files changed

+6
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+6
-0
lines changed
Open diff view settings
Collapse file

‎lib/internal/socket_list.js‎

Copy file name to clipboardExpand all lines: lib/internal/socket_list.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class SocketListSend extends EventEmitter {
88
super();
99
this.key = key;
1010
this.child = child;
11+
child.once('exit', () => this.emit('exit', this));
1112
}
1213

1314
_request(msg, cmd, callback) {
Collapse file

‎lib/net.js‎

Copy file name to clipboardExpand all lines: lib/net.js
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,6 +1664,10 @@ Server.prototype.listenFD = internalUtil.deprecate(function(fd, type) {
16641664
Server.prototype._setupSlave = function(socketList) {
16651665
this._usingSlaves = true;
16661666
this._slaves.push(socketList);
1667+
socketList.once('exit', (socketList) => {
1668+
const index = this._slaves.indexOf(socketList);
1669+
this._slaves.splice(index, 1);
1670+
});
16671671
};
16681672

16691673
Server.prototype.ref = function() {
Collapse file

‎test/parallel/test-child-process-fork-net2.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-child-process-fork-net2.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ if (process.argv[2] === 'child') {
156156
}
157157

158158
process.on('exit', function() {
159+
assert.strictEqual(server._slaves.length, 0);
159160
assert.strictEqual(disconnected, count);
160161
assert.strictEqual(connected, count);
161162
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.