Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6ece2a0

Browse filesBrowse 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 <info@bnoordhuis.nl> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
1 parent 44228df commit 6ece2a0
Copy full SHA for 6ece2a0

File tree

Expand file treeCollapse file tree

2 files changed

+11
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+11
-2
lines changed
Open diff view settings
Collapse file

‎lib/cluster.js‎

Copy file name to clipboardExpand all lines: lib/cluster.js
+6-2Lines changed: 6 additions & 2 deletions
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
}
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-cluster-debug-port.js
+5Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.