0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-cluster-worker-handle-close.js
theanarkh b532dca947
cluster: fix fd leak
PR-URL: https://github.com/nodejs/node/pull/43650
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2022-07-11 08:27:34 +01:00

28 lines
791 B
JavaScript

'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();
}));
});
}));
}