Skip to content

Commit 2132d34

Browse files
cjihrigrvagg
authored andcommitted
cluster: rewrite debug ports consistently
When debug flags are passed to clustered applications, the debug port is rewritten for each worker process to avoid collisions. Prior to this commit, each debug flag would get a unique value. This commit reworks the logic to assign the same port value to all debug flags for a single worker. PR-URL: #7050 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]>
1 parent cb2ef35 commit 2132d34

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/cluster.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ function masterInit() {
299299
function createWorkerProcess(id, env) {
300300
var workerEnv = util._extend({}, process.env);
301301
var execArgv = cluster.settings.execArgv.slice();
302+
var debugPort = 0;
302303

303304
workerEnv = util._extend(workerEnv, env);
304305
workerEnv.NODE_UNIQUE_ID = '' + id;
@@ -307,8 +308,11 @@ function masterInit() {
307308
var match = execArgv[i].match(/^(--debug|--debug-(brk|port))(=\d+)?$/);
308309

309310
if (match) {
310-
const debugPort = process.debugPort + debugPortOffset;
311-
++debugPortOffset;
311+
if (debugPort === 0) {
312+
debugPort = process.debugPort + debugPortOffset;
313+
++debugPortOffset;
314+
}
315+
312316
execArgv[i] = match[1] + '=' + debugPort;
313317
}
314318
}

test/parallel/test-cluster-debug-port.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ if (cluster.isMaster) {
2222
portSet: process.debugPort + 1
2323
}).on('exit', checkExitCode);
2424

25+
cluster.setupMaster({
26+
execArgv: [`--debug-port=${process.debugPort}`,
27+
`--debug=${process.debugPort}`]
28+
});
29+
2530
console.log('forked worker should have --debug-port, with offset = 2');
2631
cluster.fork({
2732
portSet: process.debugPort + 2

0 commit comments

Comments
 (0)