Skip to content

Commit 6ece2a0

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

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
@@ -286,6 +286,7 @@ function masterInit(){
286286
functioncreateWorkerProcess(id,env){
287287
varworkerEnv=util._extend({},process.env);
288288
varexecArgv=cluster.settings.execArgv.slice();
289+
vardebugPort=0;
289290

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

296297
if(match){
297-
constdebugPort=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‎

Lines changed: 5 additions & 0 deletions
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)