Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cluster: fix inspector port assignment #18696

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
cluster: fix inspector port assignment
Make sure that inspector ports in cluster are inside the valid range:
`[1024, 65535]`.
Fix flaky `test-inspector-port-zero-cluster`.

Fixes: #18303
  • Loading branch information
santigimeno committed Feb 18, 2018
commit efdea328c9de9a69f80d656972c001b6205c3e5c
3 changes: 3 additions & 0 deletions lib/internal/cluster/master.js
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ const intercom = new EventEmitter();
const SCHED_NONE = 1;
const SCHED_RR = 2;
const { isLegalPort } = require('internal/net');
const [ minPort, maxPort ] = [ 1024, 65535 ];

module.exports = cluster;

@@ -119,6 +120,8 @@ function createWorkerProcess(id, env) {
}
} else {
inspectPort = process.debugPort + debugPortOffset;
if (inspectPort > maxPort)
inspectPort = inspectPort - maxPort + minPort - 1;
debugPortOffset++;
}

10 changes: 10 additions & 0 deletions test/sequential/test-inspector-port-cluster.js
Original file line number Diff line number Diff line change
@@ -24,6 +24,16 @@ function testRunnerMain() {
workers: [{ expectedPort: 9230 }]
});

spawnMaster({
execArgv: ['--inspect=65534'],
workers: [
{ expectedPort: 65535 },
{ expectedPort: 1024 },
{ expectedPort: 1025 },
{ expectedPort: 1026 }
]
});

let port = debuggerPort + offset++ * 5;

spawnMaster({
10 changes: 4 additions & 6 deletions test/sequential/test-inspector-port-zero-cluster.js
Original file line number Diff line number Diff line change
@@ -30,16 +30,14 @@ function serialFork() {
if (cluster.isMaster) {
Promise.all([serialFork(), serialFork(), serialFork()])
.then(common.mustCall((ports) => {
ports.push(process.debugPort);
ports.sort();
ports.splice(0, 0, process.debugPort);
// 4 = [master, worker1, worker2, worker3].length()
assert.strictEqual(ports.length, 4);
assert(ports.every((port) => port > 0));
assert(ports.every((port) => port < 65536));
// Ports should be consecutive.
assert.strictEqual(ports[0] + 1, ports[1]);
assert.strictEqual(ports[1] + 1, ports[2]);
assert.strictEqual(ports[2] + 1, ports[3]);
assert.strictEqual(ports[0] === 65535 ? 1024 : ports[0] + 1, ports[1]);
assert.strictEqual(ports[1] === 65535 ? 1024 : ports[1] + 1, ports[2]);
assert.strictEqual(ports[2] === 65535 ? 1024 : ports[2] + 1, ports[3]);
}))
.catch(
(err) => {