mirror of https://github.com/nodejs/node.git
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: https://github.com/nodejs/node/pull/18696 Fixes: https://github.com/nodejs/node/issues/18303 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>pull/18607/merge
parent
2990429b16
commit
45982de418
|
@ -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++;
|
||||
}
|
||||
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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) => {
|
||||
|
|
Loading…
Reference in New Issue