Skip to content

Commit

Permalink
Changed: nextTick() uncaughtException handler
Browse files Browse the repository at this point in the history
allowing more time to register
  • Loading branch information
tj committed Sep 12, 2011
1 parent 8026906 commit 87e5806
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
16 changes: 13 additions & 3 deletions examples/error.js
Expand Up @@ -14,9 +14,19 @@ var server = http.createServer(function(req, res){
res.end(body); res.end(body);
}); });


cluster(server) var proc = cluster(server)
.use(cluster.debug()) .use(cluster.debug())
.use(cluster.logger())
.use(cluster.stats()) .use(cluster.stats())
.use(cluster.repl(__dirname + '/repl')) .use(cluster.repl(__dirname + '/repl'))
.listen(3000); .listen(3000);

if (proc.isChild) {
// you can register your own exceptionHandler
// which will prevent Cluster from add its own. This
// means the workers will be harder to kill, however
// if you do not employ additional logic, connections
// will remain open until timeout.
process.on('uncaughtException', function(err){
console.error(err);
});
}
28 changes: 15 additions & 13 deletions lib/worker.js
Expand Up @@ -95,20 +95,22 @@ Worker.prototype.start = function(){
process.on('SIGQUIT', this.close.bind(this)); process.on('SIGQUIT', this.close.bind(this));


// conditionally handle uncaughtException // conditionally handle uncaughtException
if (!process.listeners('uncaughtException').length) { process.nextTick(function(){
process.on('uncaughtException', function(err){ if (!process.listeners('uncaughtException').length) {
// stderr for logs process.on('uncaughtException', function(err){
console.error(err.stack || err.message); // stderr for logs

console.error(err.stack || err.message);
// report exception
self.master.call('workerException', err); // report exception

self.master.call('workerException', err);
// exit
process.nextTick(function(){ // exit
self.destroy(); process.nextTick(function(){
self.destroy();
});
}); });
}); }
} });
}; };


/** /**
Expand Down

0 comments on commit 87e5806

Please sign in to comment.