Skip to content

Commit

Permalink
cluster: fix fd leak
Browse files Browse the repository at this point in the history
PR-URL: #43650
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
theanarkh authored and targos committed Jul 12, 2022
1 parent fa5c464 commit 5d8ee51
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/internal/cluster/child.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ function onconnection(message, handle) {

if (accepted)
server.onconnection(0, handle);
else
handle.close();
}

function send(message, cb) {
Expand Down
27 changes: 27 additions & 0 deletions test/parallel/test-cluster-worker-handle-close.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';
const common = require('../common');
const cluster = require('cluster');
const net = require('net');

if (cluster.isPrimary) {
cluster.schedulingPolicy = cluster.SCHED_RR;
cluster.fork();
} else {
const server = net.createServer(common.mustNotCall());
server.listen(0, common.mustCall(() => {
net.connect(server.address().port);
}));
process.prependListener('internalMessage', common.mustCallAtLeast((message, handle) => {
if (message.act !== 'newconn') {
return;
}
// Make the worker drops the connection, see `rr` and `onconnection` in child.js
server.close();
const close = handle.close;
handle.close = common.mustCall(() => {
close.call(handle, common.mustCall(() => {
process.exit();
}));
});
}));
}

0 comments on commit 5d8ee51

Please sign in to comment.