Skip to content

Commit 6ece2a0

Browse files
cjihrigMyles Borins
authored and
Myles Borins
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 44228df commit 6ece2a0

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/cluster.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ function masterInit() {
286286
function createWorkerProcess(id, env) {
287287
var workerEnv = util._extend({}, process.env);
288288
var execArgv = cluster.settings.execArgv.slice();
289+
var debugPort = 0;
289290

290291
workerEnv = util._extend(workerEnv, env);
291292
workerEnv.NODE_UNIQUE_ID = '' + id;
@@ -294,8 +295,11 @@ function masterInit() {
294295
var match = execArgv[i].match(/^(--debug|--debug-(brk|port))(=\d+)?$/);
295296

296297
if (match) {
297-
const debugPort = process.debugPort + debugPortOffset;
298-
++debugPortOffset;
298+
if (debugPort === 0) {
299+
debugPort = process.debugPort + debugPortOffset;
300+
++debugPortOffset;
301+
}
302+
299303
execArgv[i] = match[1] + '=' + debugPort;
300304
}
301305
}

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

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ if (cluster.isMaster) {
2323
portSet: process.debugPort + 1
2424
}).on('exit', checkExitCode);
2525

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

0 commit comments

Comments
 (0)