Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a3bdd07

Browse filesBrowse files
theanarkhjuanarbol
authored andcommitted
cluster: fix cluster rr distribute error
PR-URL: #44202 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent dd08d6c commit a3bdd07
Copy full SHA for a3bdd07

File tree

Expand file treeCollapse file tree

2 files changed

+34
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+34
-0
lines changed
Open diff view settings
Collapse file

‎lib/internal/cluster/round_robin_handle.js‎

Copy file name to clipboardExpand all lines: lib/internal/cluster/round_robin_handle.js
+4Lines 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
Collapse file
+30Lines 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+
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.