GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — cluster: do not unconditionally set --debug-port · nodejs/node@423d894

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • cluster.js
  • test/parallel
    • test-cluster-debug-port.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/cluster.js‎

Copy file name to clipboardExpand all lines: lib/cluster.js
+4-6Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,11 @@ function masterInit() {
278278
cluster.emit('setup', settings);
279279
}
280280

281+
var debugPortOffset = 1;
282+
281283
function createWorkerProcess(id, env) {
282284
var workerEnv = util._extend({}, process.env);
283285
var execArgv = cluster.settings.execArgv.slice();
284-
var debugPort = process.debugPort + id;
285-
var hasDebugArg = false;
286286

287287
workerEnv = util._extend(workerEnv, env);
288288
workerEnv.NODE_UNIQUE_ID = '' + id;
@@ -291,14 +291,12 @@ function masterInit() {
291291
var match = execArgv[i].match(/^(--debug|--debug-(brk|port))(=\d+)?$/);
292292

293293
if (match) {
294+
let debugPort = process.debugPort + debugPortOffset;
295+
++debugPortOffset;
294296
execArgv[i] = match[1] + '=' + debugPort;
295-
hasDebugArg = true;
296297
}
297298
}
298299

299-
if (!hasDebugArg)
300-
execArgv = ['--debug-port=' + debugPort].concat(execArgv);
301-
302300
return fork(cluster.settings.exec, cluster.settings.args, {
303301
env: workerEnv,
304302
silent: cluster.settings.silent,
Collapse file

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

Copy file name to clipboard
+38Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const cluster = require('cluster');
5+
6+
if (cluster.isMaster) {
7+
assert.strictEqual(process.execArgv.length, 0, 'run test with no args');
8+
9+
function checkExitCode(code, signal) {
10+
assert.strictEqual(code, 0);
11+
assert.strictEqual(signal, null);
12+
}
13+
14+
console.log('forked worker should not have --debug-port');
15+
cluster.fork().on('exit', checkExitCode);
16+
17+
cluster.setupMaster({
18+
execArgv: ['--debug-port=' + process.debugPort]
19+
});
20+
21+
console.log('forked worker should have --debug-port, with offset = 1');
22+
cluster.fork({
23+
portSet: process.debugPort + 1
24+
}).on('exit', checkExitCode);
25+
26+
console.log('forked worker should have --debug-port, with offset = 2');
27+
cluster.fork({
28+
portSet: process.debugPort + 2
29+
}).on('exit', checkExitCode);
30+
} else {
31+
const hasDebugArg = process.execArgv.some(function(arg) {
32+
return /debug/.test(arg);
33+
});
34+
35+
assert.strictEqual(hasDebugArg, process.env.portSet !== undefined);
36+
assert.strictEqual(process.debugPort, +process.env.portSet || 5858);
37+
process.exit();
38+
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.