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 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
14 changes: 13 additions & 1 deletion lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ cluster.Worker = Worker;
cluster.isWorker = ('NODE_UNIQUE_ID' in process.env);
cluster.isMaster = (cluster.isWorker === false);

const kDebugPortMin = 1024;
const kDebugPortMax = 65535;

function Worker(options) {
if (!(this instanceof Worker))
Expand Down Expand Up @@ -279,10 +281,20 @@ function masterInit() {
cluster.emit('setup', settings);
}

var nextDebugPort = process.debugPort;

function getDebugPort() {
++nextDebugPort;
if (nextDebugPort > kDebugPortMax) {
nextDebugPort = kDebugPortMin;
}
return nextDebugPort;
}

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

workerEnv = util._extend(workerEnv, env);
Expand Down
19 changes: 19 additions & 0 deletions test/parallel/test-cluster-debugport-overflow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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);
});
} else {
process.exit(42);
}
} else {
// iojs --debug-port=65535 test-cluster-debugport-overflow.js master
var args = ['--debug-port=65535', __filename, 'master'];
spawn(process.argv[0], args).on('close', function(code) {
assert.equal(42, code, 'Worker was started');
});
}