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: sometimes debug-port value for child process can be broken #1524

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ cluster.Worker = Worker;
cluster.isWorker = ('NODE_UNIQUE_ID' in process.env);
cluster.isMaster = (cluster.isWorker === false);

const debugPortRange = (65536 - 1024);

function Worker(options) {
if (!(this instanceof Worker))
Expand Down Expand Up @@ -282,7 +283,7 @@ function masterInit() {
function createWorkerProcess(id, env) {
var workerEnv = util._extend({}, process.env);
var execArgv = cluster.settings.execArgv.slice();
var debugPort = process.debugPort + id;
var debugPort = (process.debugPort + id) % debugPortRange + 1024;
Copy link
Member

Choose a reason for hiding this comment

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

It would be a little neater to turn the number literal into a constant and use it in the range calculation above.

Aside, it's something of a (not consistently enforced) convention to name constants kFoo, i.e.:

const kDebugPortStart = 1024;
const kDebugPortRange = (65536 - kDebugPortStart);

var hasDebugArg = false;

workerEnv = util._extend(workerEnv, env);
Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-cluster-debugport-overflow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var spawn = require('child_process').spawn;
var cluster = require('cluster');
var assert = require('assert');

if (process.argv[2] == 'master') {
if (cluster.isMaster) {
cluster.fork().on('exit', function(code) {
process.exit(code);
})
Copy link
Contributor

Choose a reason for hiding this comment

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

style: semicolon

} else {
process.exit(42);
}
} else {
// iojs --debug-port=65535 test-cluster-debugport-overflow.js master
spawn(process.argv[0], ['--debug-port=65535', __filename, 'master']).on('close', function(code){
Copy link
Member

Choose a reason for hiding this comment

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

Style nits: line > 80 columns and missing space before brace. If you assign the arguments to a var args first, you stay under the limit.

Ditto for the line in lib/cluster.js; eyeballing it, it looks to be just over 80 columns.

assert.equal(42, code, 'Worker was started');
});
}