Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Rewrite from scratch. Debug port numbers must be consecutive.
  • Loading branch information
Olegas committed Apr 27, 2015
commit 4aa3f47c4fc10f736a3811e02d3564043e46ca56
18 changes: 13 additions & 5 deletions lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ cluster.Worker = Worker;
cluster.isWorker = ('NODE_UNIQUE_ID' in process.env);
cluster.isMaster = (cluster.isWorker === false);

const kDebugPortStart = 1024;
const kDebugPortRange = (65536 - kDebugPortStart);
const kDebugPortMin = 1024;
const kDebugPortMax = 65535;

function Worker(options) {
if (!(this instanceof Worker))
Expand Down Expand Up @@ -281,14 +281,22 @@ 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;

debugPort = debugPort % kDebugPortRange + kDebugPortStart;

workerEnv = util._extend(workerEnv, env);
workerEnv.NODE_UNIQUE_ID = '' + id;

Expand Down