diff --git a/lib/cli.js b/lib/cli.js index 55098049..9229b29a 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -32,7 +32,7 @@ program , Number , 7400) .option('--max-port ' - , 'maximum port number for worker use (total must be multiple of 3)' + , 'maximum port number for worker use' , Number , 7700) .option('--public-ip ' diff --git a/lib/roles/provider.js b/lib/roles/provider.js index 52eeb9c5..b8c931ea 100644 --- a/lib/roles/provider.js +++ b/lib/roles/provider.js @@ -27,6 +27,10 @@ module.exports = function(options) { } var totalsTimer + // To make sure that we always bind the same type of service to the same + // port, we must ensure that we allocate ports in fixed groups. + var ports = options.ports.slice(0, -options.ports.length % 3) + // Information about total devices var delayedTotals = (function() { function totals() { @@ -261,8 +265,8 @@ module.exports = function(options) { // Spawn a device worker function spawn() { - var ports = options.ports.splice(0, 3) - , proc = options.fork(device, ports) + var allocatedPorts = ports.splice(0, 3) + , proc = options.fork(device, allocatedPorts) , resolver = Promise.defer() function exitListener(code, signal) { @@ -323,7 +327,7 @@ module.exports = function(options) { proc.removeListener('message', messageListener) // Return used ports to the main pool - Array.prototype.push.apply(options.ports, ports) + Array.prototype.push.apply(ports, allocatedPorts) // Update lists _.pull(lists.ready, device.id)