This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
How to end cluster's worker process gracefully? #2088
Labels
Comments
Call |
Well, but we need to syncronize end of all async actions in program because var cluster = require('cluster');
var http = require('http');
if (cluster.isMaster) {
cluster.fork();
cluster.on('death', function(worker) {
console.log('worker ' + worker.pid + ' died');
});
} else {
var semaphore = new Semaphore(1)
semaphore.on('zero', function() {
process.exit()
})
var server = http.Server(function(req, res) {
/* ... */
semaphore.inc()
try {
smthAsyncAction(function() {
semaphore.dec()
})
} catch(e) {
semaphore.dec()
throw e
}
/* ... */
}).listen(8000);
server.on('end', function() {
semaphore.dec()
})
} but our code would be much easier if there was a method like var cluster = require('cluster');
var http = require('http');
if (cluster.isMaster) {
cluster.fork();
cluster.on('death', function(worker) {
console.log('worker ' + worker.pid + ' died');
});
} else {
var server = http.Server(function(req, res) {
/* ... */
smthAsyncAction(function() {
/* ... */
})
/* ... */
}).listen(8000);
server.on('end', function() {
cluster.ipc.close()
})
} |
I'm working on this in #2038 but I don't know how to close the IPC between master and worker. Can someone give me a hint? |
Closed
It just got an inspiration |
We can't take API changes in v0.6, sorry. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
How i can cause exit of worker process (end worker's event loop) without calling
process.exit()
?Result
Expected result:
The text was updated successfully, but these errors were encountered: