Skip to content

Commit

Permalink
* Added more verbosity to worker recycle
Browse files Browse the repository at this point in the history
* Changed logs to always reference the workers pid
* Fixed bug where worker would try to send a request notification even if the
master was already disconnected.
  • Loading branch information
nullivex committed Dec 29, 2014
1 parent 729586f commit c909505
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,11 @@ $ DEBUG=infant* node app

## Changelog

### 0.9.2
### 0.9.3
* Added more verbosity to worker recycle
* Changed logs to always reference the workers pid
* Fixed bug where worker would try to send a request notification even if the
master was already disconnected.

### 0.9.1
* Fixed a bug where worker recycle wasnt properly using `worker.disconnect()`
Expand Down
32 changes: 17 additions & 15 deletions helpers/Cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Cluster.prototype.setupWorker = function(worker){
){
worker.recycling = true
debug(
'Worker ' + worker.id +
'Worker ' + worker.process.pid +
' has reached its connection limit, recycling',
that.counters[worker.id])
//spawn a new worker now
Expand All @@ -167,17 +167,18 @@ Cluster.prototype.setupWorker = function(worker){
if(that.options.enhanced){
//set a timeout to kill the worker so we dont bleed workers
var disconnectTimeout = setTimeout(function(){
debug('worker ' + worker.id + ' recycle timeout exceeded... ' +
'killed. recycle complete')
worker.kill()
debug('worker ' + worker.process.pid + ' recycle timeout ' +
'exceeded... killed. recycle complete')
worker.kill('SIGKILL')
},that.options.recycleTimeout || 5000)
worker.on('disconnect',function(){
clearTimeout(disconnectTimeout)
debug('worker ' + worker.id + ' recycled successfully!')
debug('worker ' + worker.process.pid + ' recycled successfully!')
worker.kill('SIGKILL')
})
worker.disconnect()
} else {
worker.kill()
worker.kill('SIGKILL')
}
}
newWorker.on('message',startedListener)
Expand All @@ -196,13 +197,13 @@ Cluster.prototype.start = function(done){
var online = 0
//handler initial workers coming online
var workerStart = function(worker){
debug('Worker ' + worker.id + ' online')
debug('Worker ' + worker.process.pid + ' online')
//in enhanced mode we wait for the worker to confirm its started
if(that.options.enhanced){
worker.once('message',function(msg){
debug('got message from ' + worker.id,msg)
debug('got message from ' + worker.process.pid,msg)
if('started' === msg.status){
debug('Worker ' + worker.id + ' started')
debug('Worker ' + worker.process.pid + ' started')
online++
if(online >= that.count && !that.running){
deferred.resolve()
Expand Down Expand Up @@ -251,7 +252,7 @@ Cluster.prototype.start = function(done){
*/
Cluster.prototype.respawn = function(worker,code,signal){
var that = this
debug('Worker ' + worker.id + ' exited',code,signal)
debug('Worker ' + worker.process.pid + ' exited',code,signal)
//remove the counter
delete that.counters[worker.id]
that.emit('exit',worker,code,signal)
Expand All @@ -261,16 +262,16 @@ Cluster.prototype.respawn = function(worker,code,signal){
that.running &&
that.options.respawn
){
debug('Worker ' + worker.id +
debug('Worker ' + worker.process.pid +
' died (' + (signal || code) + ') and is respawn eligible, restarting')
that.cluster.once('online',function(worker){
debug('Worker ' + worker.id + ' is now online')
debug('Worker ' + worker.process.pid + ' is now online')
that.emit('respawn',worker,code,signal)
})
//start the new worker
that.fork()
} else {
debug('Worker ' + worker.id +
debug('Worker ' + worker.process.pid +
' died (' + (signal || code) + ') and is not respawn eligible, exiting')
}
}
Expand Down Expand Up @@ -351,7 +352,8 @@ Cluster.prototype.stop = function(done){
Cluster.prototype.kill = function(signal){
var that = this
that.each(function(worker){
debug(that.module,'sending worker pid ' + worker.process.pid + ' kill')
debug(that.module,'sending worker ' + worker.process.pid +
' kill (' + signal + ')')
worker.kill(signal || 'SIGTERM')
})
}
Expand Down Expand Up @@ -465,7 +467,7 @@ module.exports.setup = function(server,title,start,stop){
debug('start finished')
if(process.send) process.send({status: 'started'})
server.on('request',function(){
if(process.send) process.send('request')
if(process.send && process.connected) process.send('request')
})
})
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "SnailJS <developers@snailjs.org>",
"name": "infant",
"description": "Child process, and cluster helper for Node.js",
"version": "0.9.2",
"version": "0.9.3",
"homepage": "http://snailjs.org/",
"repository": {
"type": "git",
Expand Down

0 comments on commit c909505

Please sign in to comment.