fugue
fugue copied to clipboard
Throw Exception when kill worker process
In my code, I spawn 5 workers. The app server has an internal counter. If it exceeds 20, then it will app.close(), then process.exit() after 1 second, to make sure all existing request of the app are probably handle before the process ends. so that fugue can respawn the worker again.
here is my code:
app.get('/test', function(sReq, sRes) { try { var myCounter = counter ++; console.log('test is called ' + myCounter);
if (myCounter >= 20) {
if (isServerClose) {
console.log("--- server is closed --- " + myCounter);
try {
sRes.send('ERROR 1 ');
} catch (ex) {
console.log(ex);
}
} else {
isServerClose = true;
var pids = fugue.workerPids();
console.log("--- server is going to stop --- " + myCounter + " Worker Id: " + fugue.workerId() + " ProcessId: " + process.pid );
try {
sRes.send('ERROR 2 ');
} catch (ex) {
console.log(ex);
}
app.close();
if (! fugue.isMaster()) {
setTimeout(function() {process.exit();}, 1000);
}
}
} else {
if (isServerClose) {
console.log("--- server is closed --- " + myCounter);
try {
sRes.send('ERROR 3 ');
} catch (ex) {
console.log(ex);
}
} else {
sRes.send('TEST');
}
}
} catch (ex2) {
console.log("bigger problem now... " + JSON.stringify(ex2));
}
});
When I do the test, let say , make 500 requests. Then it will crash.
net.js:841
throw new Error('The connection is not writable');
^
Error: The connection is not writable
at Socket._shutdown (net.js:841:11)
at Socket.flush (net.js:521:12)
at Socket.end (net.js:873:14)
at Carrier.
I think conn.end() call when the process doesn't exist anymore.
I don't know if it is a bug, or I kill the process in a wrong way. Please advice.