Skip to content

Commit a3bdd07

Browse files
theanarkhjuanarbol
authored andcommitted
cluster: fix cluster rr distribute error
PR-URL: #44202 Reviewed-By: James M Snell <[email protected]>
1 parent dd08d6c commit a3bdd07

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

‎lib/internal/cluster/round_robin_handle.js‎

Lines changed: 4 additions & 0 deletions
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
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Flags: --expose-internals
2+
'use strict';
3+
constcommon=require('../common');
4+
constassert=require('assert');
5+
constnet=require('net');
6+
constcluster=require('cluster');
7+
constrr=require('internal/cluster/round_robin_handle');
8+
9+
if(cluster.isPrimary){
10+
constdistribute=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+
constserver=net.createServer(common.mustNotCall());
20+
server.listen(0,common.mustCall(()=>{
21+
22+
constsocket=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)