Skip to content

Commit

Permalink
prevent duplicate ports to queue resolves terascope#622
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnoble committed Nov 29, 2017
1 parent 0301363 commit a7e746d
Showing 1 changed file with 9 additions and 25 deletions.
34 changes: 9 additions & 25 deletions lib/cluster/node_master.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,22 +254,7 @@ module.exports = function module(context) {

messaging.register({
event: 'child:exit',
callback: (worker) => {
// reclaim ports
if (worker.slicer_port) {
logger.debug(`reclaiming port ${worker.slicer_port} from slicer exit`);
// reclaim port if slicer exits, if slicer tries to restart it will exit and
// mark the job as failed
systemPorts.addPort(worker.slicer_port);
}
// used to catch slicer shutdown to allow retry, allows to bypass the
// jobRequest requestedWorkers
if (worker.assignment === 'slicer' && newWorkerQueue.size()) {
context.foundation.startWorkers(1, newWorkerQueue.dequeue());
} else {
sendNodeState();
}
}
callback: () => sendNodeState()
});

function killWorkers(filterFn) {
Expand Down Expand Up @@ -317,17 +302,16 @@ module.exports = function module(context) {
portQueue.enqueue(i);
}

function getPort() {
return portQueue.dequeue();
}

function addPort(port) {
portQueue.enqueue(port);
function getPort(preventEnqueing) {
const port = portQueue.dequeue();
if(!preventEnqueing) {
portQueue.enqueue(port)
}
return port
}

return {
getPort,
addPort
getPort
};
}

Expand Down Expand Up @@ -375,7 +359,7 @@ module.exports = function module(context) {
messaging.initialize();

if (context.sysconfig.teraslice.master) {
const assetsPort = systemPorts.getPort();
const assetsPort = systemPorts.getPort(true);

logger.debug(`node ${context.sysconfig._nodeName} is creating the cluster_master`);
context.foundation.startWorkers(1, {
Expand Down

0 comments on commit a7e746d

Please sign in to comment.