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 1929d5b

Browse filesBrowse files
Trottrvagg
authored andcommitted
lib: fix cluster handle leak
It is possible to cause a resource leak in SharedHandle. This commit fixes the leak. Fixes: #2510 PR-URL: #3510 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent 4c9abbd commit 1929d5b
Copy full SHA for 1929d5b

File tree

Expand file treeCollapse file tree

2 files changed

+57
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+57
-1
lines changed
Open diff view settings
Collapse file

‎lib/cluster.js‎

Copy file name to clipboardExpand all lines: lib/cluster.js
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,10 @@ function masterInit() {
345345
* if it has disconnected, otherwise we might
346346
* still want to access it.
347347
*/
348-
if (!worker.isConnected()) removeWorker(worker);
348+
if (!worker.isConnected()) {
349+
removeHandlesForWorker(worker);
350+
removeWorker(worker);
351+
}
349352

350353
worker.suicide = !!worker.suicide;
351354
worker.state = 'dead';
Collapse file
+53Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// In Node 4.2.1 on operating systems other than Linux, this test triggers an
2+
// assertion in cluster.js. The assertion protects against memory leaks.
3+
// https://github.com/nodejs/node/pull/3510
4+
5+
'use strict';
6+
const common = require('../common');
7+
const assert = require('assert');
8+
const net = require('net');
9+
const cluster = require('cluster');
10+
cluster.schedulingPolicy = cluster.SCHED_NONE;
11+
12+
if (cluster.isMaster) {
13+
var conn, worker1, worker2;
14+
15+
worker1 = cluster.fork();
16+
worker1.on('message', common.mustCall(function() {
17+
worker2 = cluster.fork();
18+
conn = net.connect(common.PORT, common.mustCall(function() {
19+
worker1.send('die');
20+
worker2.send('die');
21+
}));
22+
conn.on('error', function(e) {
23+
// ECONNRESET is OK
24+
if (e.code !== 'ECONNRESET')
25+
throw e;
26+
});
27+
}));
28+
29+
cluster.on('exit', function(worker, exitCode, signalCode) {
30+
assert(worker === worker1 || worker === worker2);
31+
assert.strictEqual(exitCode, 0);
32+
assert.strictEqual(signalCode, null);
33+
if (Object.keys(cluster.workers).length === 0)
34+
conn.destroy();
35+
});
36+
37+
return;
38+
}
39+
40+
var server = net.createServer(function(c) {
41+
c.end('bye');
42+
});
43+
44+
server.listen(common.PORT, function() {
45+
process.send('listening');
46+
});
47+
48+
process.on('message', function(msg) {
49+
if (msg !== 'die') return;
50+
server.close(function() {
51+
setImmediate(() => process.disconnect());
52+
});
53+
});

0 commit comments

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