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 4fa1f31

Browse filesBrowse files
santigimenoaddaleax
authored andcommitted
cluster: fix inspector port assignment
Make sure that inspector ports in cluster are inside the valid range: `[1024, 65535]`. Fixes flaky `test-inspector-port-zero-cluster`. PR-URL: #18696 Fixes: #18303 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 205a84c commit 4fa1f31
Copy full SHA for 4fa1f31

File tree

Expand file treeCollapse file tree

3 files changed

+17
-6
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+17
-6
lines changed
Open diff view settings
Collapse file

‎lib/internal/cluster/master.js‎

Copy file name to clipboardExpand all lines: lib/internal/cluster/master.js
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const intercom = new EventEmitter();
1414
const SCHED_NONE = 1;
1515
const SCHED_RR = 2;
1616
const { isLegalPort } = require('internal/net');
17+
const [ minPort, maxPort ] = [ 1024, 65535 ];
1718

1819
module.exports = cluster;
1920

@@ -119,6 +120,8 @@ function createWorkerProcess(id, env) {
119120
}
120121
} else {
121122
inspectPort = process.debugPort + debugPortOffset;
123+
if (inspectPort > maxPort)
124+
inspectPort = inspectPort - maxPort + minPort - 1;
122125
debugPortOffset++;
123126
}
124127

Collapse file

‎test/sequential/test-inspector-port-cluster.js‎

Copy file name to clipboardExpand all lines: test/sequential/test-inspector-port-cluster.js
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ function testRunnerMain() {
2424
workers: [{ expectedPort: 9230 }]
2525
});
2626

27+
spawnMaster({
28+
execArgv: ['--inspect=65534'],
29+
workers: [
30+
{ expectedPort: 65535 },
31+
{ expectedPort: 1024 },
32+
{ expectedPort: 1025 },
33+
{ expectedPort: 1026 }
34+
]
35+
});
36+
2737
let port = debuggerPort + offset++ * 5;
2838

2939
spawnMaster({
Collapse file

‎test/sequential/test-inspector-port-zero-cluster.js‎

Copy file name to clipboardExpand all lines: test/sequential/test-inspector-port-zero-cluster.js
+4-6Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@ function serialFork() {
3030
if (cluster.isMaster) {
3131
Promise.all([serialFork(), serialFork(), serialFork()])
3232
.then(common.mustCall((ports) => {
33-
ports.push(process.debugPort);
34-
ports.sort();
33+
ports.splice(0, 0, process.debugPort);
3534
// 4 = [master, worker1, worker2, worker3].length()
3635
assert.strictEqual(ports.length, 4);
3736
assert(ports.every((port) => port > 0));
3837
assert(ports.every((port) => port < 65536));
39-
// Ports should be consecutive.
40-
assert.strictEqual(ports[0] + 1, ports[1]);
41-
assert.strictEqual(ports[1] + 1, ports[2]);
42-
assert.strictEqual(ports[2] + 1, ports[3]);
38+
assert.strictEqual(ports[0] === 65535 ? 1024 : ports[0] + 1, ports[1]);
39+
assert.strictEqual(ports[1] === 65535 ? 1024 : ports[1] + 1, ports[2]);
40+
assert.strictEqual(ports[2] === 65535 ? 1024 : ports[2] + 1, ports[3]);
4341
}))
4442
.catch(
4543
(err) => {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.