Skip to content
Permalink
Browse files
cluster: fix cluster rr distribute error
PR-URL: #44202
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
theanarkh authored and RafaelGSS committed Sep 5, 2022
1 parent 78c6827 commit 3c5354869e993ab645f85a2c73ce72f8af014de2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
@@ -98,6 +98,10 @@ RoundRobinHandle.prototype.remove = function(worker) {
};

RoundRobinHandle.prototype.distribute = function(err, handle) {
// If `accept` fails just skip it (handle is undefined)
if (err) {
return;
}
append(this.handles, handle);
// eslint-disable-next-line node-core/no-array-destructuring
const [ workerEntry ] = this.free; // this.free is a SafeMap
@@ -0,0 +1,30 @@
// Flags: --expose-internals
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const cluster = require('cluster');
const rr = require('internal/cluster/round_robin_handle');

if (cluster.isPrimary) {
const distribute = rr.prototype.distribute;
rr.prototype.distribute = function(err, handle) {
assert.strictEqual(err, 0);
handle.close();
distribute.call(this, -1, undefined);
};
cluster.schedulingPolicy = cluster.SCHED_RR;
cluster.fork();
} else {
const server = net.createServer(common.mustNotCall());
server.listen(0, common.mustCall(() => {

const socket = net.connect(server.address().port);

socket.on('close', common.mustCall(() => {
server.close(common.mustCall(() => {
process.disconnect();
}));
}));
}));
}

0 comments on commit 3c53548

Please sign in to comment.