Skip to content

Commit 97033f0

Browse files
committed
cluster: fix fd leak
1 parent 736a7d8 commit 97033f0

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/internal/cluster/child.js

+2
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ function onconnection(message, handle) {
210210

211211
if (accepted)
212212
server.onconnection(0, handle);
213+
else
214+
handle.close();
213215
}
214216

215217
function send(message, cb) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
'use strict';
3+
4+
const common = require('../common');
5+
const cluster = require('cluster');
6+
const net = require('net');
7+
8+
if (cluster.isPrimary) {
9+
cluster.schedulingPolicy = cluster.SCHED_RR;
10+
cluster.fork();
11+
} else {
12+
const server = net.createServer(common.mustNotCall());
13+
server.listen(0, common.mustCall(() => {
14+
net.connect(server.address().port);
15+
}));
16+
process.prependListener('internalMessage', common.mustCallAtLeast((message, handle) => {
17+
if (message.act !== 'newconn') {
18+
return;
19+
}
20+
// Make the worker drops the connection, see `rr` and `onconnection` in child.js
21+
server.close();
22+
const close = handle.close;
23+
handle.close = common.mustCall(() => {
24+
close.call(handle, common.mustCall(() => {
25+
process.exit();
26+
}));
27+
});
28+
}));
29+
}

0 commit comments

Comments
 (0)