GeezerVison is showing github.com — cluster: fix inspector port assignment · nodejs/node@bf4d074
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/cluster/master.js +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,6 +14,7 @@ const intercom = new EventEmitter(); | 14 | 14 | const SCHED_NONE = 1; | 15 | 15 | const SCHED_RR = 2; | 16 | 16 | const { isLegalPort } = require('internal/net'); | | 17 | +const [ minPort, maxPort ] = [ 1024, 65535 ]; | 17 | 18 |
| 18 | 19 | module.exports = cluster; | 19 | 20 |
| @@ -119,6 +120,8 @@ function createWorkerProcess(id, env) { | 119 | 120 | } | 120 | 121 | } else { | 121 | 122 | inspectPort = process.debugPort + debugPortOffset; | | 123 | + if (inspectPort > maxPort) | | 124 | + inspectPort = inspectPort - maxPort + minPort - 1; | 122 | 125 | debugPortOffset++; | 123 | 126 | } | 124 | 127 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-inspector-port-cluster.js +10Lines changed: 10 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -24,6 +24,16 @@ function testRunnerMain() { | 24 | 24 | workers: [{ expectedPort: 9230 }] | 25 | 25 | }); | 26 | 26 |
| | 27 | + spawnMaster({ | | 28 | + execArgv: ['--inspect=65534'], | | 29 | + workers: [ | | 30 | + { expectedPort: 65535 }, | | 31 | + { expectedPort: 1024 }, | | 32 | + { expectedPort: 1025 }, | | 33 | + { expectedPort: 1026 } | | 34 | + ] | | 35 | + }); | | 36 | + | 27 | 37 | let port = debuggerPort + offset++ * 5; | 28 | 38 |
| 29 | 39 | spawnMaster({ | |
Collapse file 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 number | Diff line number | Diff line change |
|---|
@@ -30,16 +30,14 @@ function serialFork() { | 30 | 30 | if (cluster.isMaster) { | 31 | 31 | Promise.all([serialFork(), serialFork(), serialFork()]) | 32 | 32 | .then(common.mustCall((ports) => { | 33 | | - ports.push(process.debugPort); | 34 | | - ports.sort(); | | 33 | + ports.splice(0, 0, process.debugPort); | 35 | 34 | // 4 = [master, worker1, worker2, worker3].length() | 36 | 35 | assert.strictEqual(ports.length, 4); | 37 | 36 | assert(ports.every((port) => port > 0)); | 38 | 37 | 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]); | 43 | 41 | })) | 44 | 42 | .catch( | 45 | 43 | (err) => { | |
|