Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cluster: do not unconditionally set --debug-port #1949

Merged
merged 1 commit into from
Jun 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,11 @@ function masterInit() {
cluster.emit('setup', settings);
}

var debugPortOffset = 1;

function createWorkerProcess(id, env) {
var workerEnv = util._extend({}, process.env);
var execArgv = cluster.settings.execArgv.slice();
var debugPort = process.debugPort + id;
var hasDebugArg = false;

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

if (match) {
let debugPort = process.debugPort + debugPortOffset;
++debugPortOffset;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no any range checking. I still think we need it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not really the point of this PR. There have been a few other PRs that have attempted to add checking, and they are still open.

execArgv[i] = match[1] + '=' + debugPort;
hasDebugArg = true;
}
}

if (!hasDebugArg)
execArgv = ['--debug-port=' + debugPort].concat(execArgv);

return fork(cluster.settings.exec, cluster.settings.args, {
env: workerEnv,
silent: cluster.settings.silent,
Expand Down
38 changes: 38 additions & 0 deletions test/parallel/test-cluster-debug-port.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const cluster = require('cluster');

if (cluster.isMaster) {
assert.strictEqual(process.execArgv.length, 0, 'run test with no args');

function checkExitCode(code, signal) {
assert.strictEqual(code, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add assert.strictEqual(signal, null) here?

assert.strictEqual(signal, null);
}

console.log('forked worker should not have --debug-port');
cluster.fork().on('exit', checkExitCode);

cluster.setupMaster({
execArgv: ['--debug-port=' + process.debugPort]
});

console.log('forked worker should have --debug-port, with offset = 1');
cluster.fork({
portSet: process.debugPort + 1
}).on('exit', checkExitCode);

console.log('forked worker should have --debug-port, with offset = 2');
cluster.fork({
portSet: process.debugPort + 2
}).on('exit', checkExitCode);
} else {
const hasDebugArg = process.execArgv.some(function(arg) {
return /debug/.test(arg);
});

assert.strictEqual(hasDebugArg, process.env.portSet !== undefined);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we really do this check? We are using a default value anyway in the next test right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we should do this check to make sure that a debug argument is not always passed to the worker.

assert.strictEqual(process.debugPort, +process.env.portSet || 5858);
process.exit();
}