mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
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>
This commit is contained in:
1 parent
c8706f3a7f
commit
97f4cc7766
2 files changed
+29
No files matched your search
@@ -210,6 +210,8 @@ function onconnection(message, handle) {
|
||||
|
||||
if (accepted)
|
||||
server.onconnection(0, handle);
|
||||
else
|
||||
handle.close();
|
||||
}
|
||||
|
||||
function send(message, cb) {
|
||||
|
||||
@@ -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();
|
||||
}));
|
||||
});
|
||||
}));
|
||||
}
|
||||
Reference in new issue
Block a user