Skip to content

Commit 3c53548

Browse files
theanarkhRafaelGSS
authored andcommitted
cluster: fix cluster rr distribute error
PR-URL: #44202 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 78c6827 commit 3c53548

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

lib/internal/cluster/round_robin_handle.js

+4
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ RoundRobinHandle.prototype.remove = function(worker) {
9898
};
9999

100100
RoundRobinHandle.prototype.distribute = function(err, handle) {
101+
// If `accept` fails just skip it (handle is undefined)
102+
if (err) {
103+
return;
104+
}
101105
append(this.handles, handle);
102106
// eslint-disable-next-line node-core/no-array-destructuring
103107
const [ workerEntry ] = this.free; // this.free is a SafeMap
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Flags: --expose-internals
2+
'use strict';
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const net = require('net');
6+
const cluster = require('cluster');
7+
const rr = require('internal/cluster/round_robin_handle');
8+
9+
if (cluster.isPrimary) {
10+
const distribute = rr.prototype.distribute;
11+
rr.prototype.distribute = function(err, handle) {
12+
assert.strictEqual(err, 0);
13+
handle.close();
14+
distribute.call(this, -1, undefined);
15+
};
16+
cluster.schedulingPolicy = cluster.SCHED_RR;
17+
cluster.fork();
18+
} else {
19+
const server = net.createServer(common.mustNotCall());
20+
server.listen(0, common.mustCall(() => {
21+
22+
const socket = net.connect(server.address().port);
23+
24+
socket.on('close', common.mustCall(() => {
25+
server.close(common.mustCall(() => {
26+
process.disconnect();
27+
}));
28+
}));
29+
}));
30+
}

0 commit comments

Comments
 (0)