Skip to content

Commit c4f80c1

Browse files
committed
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 2369f89 commit c4f80c1

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;
@@ -309,8 +310,11 @@ function masterInit() {
309310
);
310311

311312
if (match) {
312-
const debugPort = process.debugPort + debugPortOffset;
313-
++debugPortOffset;
313+
if (debugPort === 0) {
314+
debugPort = process.debugPort + debugPortOffset;
315+
++debugPortOffset;
316+
}
317+
314318
execArgv[i] = match[1] + '=' + debugPort;
315319
}
316320
}

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)