clusterflock
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -31,28 +31,44 @@ var cluster = require('cluster'), | ||
function setupSignalHandlers(options) { | ||
var isShuttingDown; | ||
process.on('SIGINT', function() { | ||
logfmt.log({ evt: 'received SIGINT, sending myself SIGTERM' }); | ||
process.kill(process.pid, 'SIGTERM'); | ||
if (isShuttingDown) { | ||
logfmt.log({ evt: 'received SIGINT, ignoring (already shutting down)' }); | ||
} else { | ||
logfmt.log({ evt: 'received SIGINT, sending myself SIGTERM' }); | ||
process.kill(process.pid, 'SIGTERM'); | ||
} | ||
}); | ||
process.on('SIGTERM', function() { | ||
logfmt.log({ evt: 'received SIGTERM, sending myself SIGQUIT' }); | ||
process.kill(process.pid, 'SIGQUIT'); | ||
if (isShuttingDown) { | ||
logfmt.log({ evt: 'received SIGTERM, ignoring (already shutting down)' }); | ||
} else { | ||
logfmt.log({ evt: 'received SIGTERM, sending myself SIGQUIT' }); | ||
process.kill(process.pid, 'SIGQUIT'); | ||
} | ||
}); | ||
process.on('SIGQUIT', function() { | ||
logfmt.log({ evt: 'received SIGQUIT, attempting graceful shutdown' }); | ||
if (isShuttingDown) { | ||
logfmt.log({ evt: 'received SIGQUIT, ignoring (already shutting down)' }); | ||
} else { | ||
logfmt.log({ evt: 'received SIGQUIT, attempting graceful shutdown' }); | ||
setTimeout(function() { | ||
logfmt.log({ evt: 'timeout exceeded, forcing shutdown' }); | ||
isShuttingDown = true; | ||
eachWorker(function(worker) { | ||
worker.kill(); | ||
}); | ||
setTimeout(function() { | ||
logfmt.log({ evt: 'timeout exceeded, forcing shutdown' }); | ||
process.kill(); | ||
}, options.timeout).unref(); | ||
eachWorker(function(worker) { | ||
worker.kill(); | ||
}); | ||
cluster.disconnect(function() { | ||
logfmt.log({ evt: 'all workers disconnected' }); | ||
}); | ||
process.kill(); | ||
}, options.timeout).unref(); | ||
cluster.disconnect(function() { | ||
logfmt.log({ evt: 'all workers disconnected' }); | ||
}); | ||
} | ||
}); | ||
@@ -59,0 +75,0 @@ } |
{ | ||
"name": "clusterflock", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "a clustering http server for node", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -16,2 +16,3 @@ require('./spec-helper'); | ||
cluster.fork = jasmine.createSpy(); | ||
cluster.worker = {}; | ||
cluster['@noCallThru'] = true | ||
@@ -81,2 +82,20 @@ master = proxyquire('../lib/master', { './logfmt': logfmt, 'cluster': cluster }); | ||
it('logs subsequent SIGINT ignores', function() { | ||
master({}); | ||
process.emit('SIGINT'); | ||
process.emit('SIGQUIT'); | ||
spyOn(logfmt, 'log'); | ||
process.emit('SIGINT'); | ||
expect(logfmt.log).toHaveBeenCalledWith({ evt: 'received SIGINT, ignoring (already shutting down)' }); | ||
}); | ||
it('does not forward subsequent SIGINTS', function() { | ||
master({}); | ||
process.emit('SIGINT'); | ||
process.emit('SIGQUIT'); | ||
process.kill.reset() | ||
process.emit('SIGINT'); | ||
expect(process.kill.callCount).toEqual(0); | ||
}); | ||
it('traps and logs SIGTERM', function() { | ||
@@ -95,2 +114,20 @@ master({}); | ||
it('logs subsequent SIGTERM ignores', function() { | ||
master({}); | ||
process.emit('SIGTERM'); | ||
process.emit('SIGQUIT'); | ||
spyOn(logfmt, 'log'); | ||
process.emit('SIGTERM'); | ||
expect(logfmt.log).toHaveBeenCalledWith({ evt: 'received SIGTERM, ignoring (already shutting down)' }); | ||
}); | ||
it('does not forward subsequent SIGTERMS', function() { | ||
master({}); | ||
process.emit('SIGTERM'); | ||
process.emit('SIGQUIT'); | ||
process.kill.reset() | ||
process.emit('SIGTERM'); | ||
expect(process.kill.callCount).toEqual(0); | ||
}); | ||
it('traps and logs SIGQUIT', function() { | ||
@@ -110,2 +147,18 @@ master({}); | ||
it('logs subsequent SIGQUIT ignores', function() { | ||
master({}); | ||
process.emit('SIGQUIT'); | ||
spyOn(logfmt, 'log'); | ||
process.emit('SIGQUIT'); | ||
expect(logfmt.log).toHaveBeenCalledWith({ evt: 'received SIGQUIT, ignoring (already shutting down)' }); | ||
}); | ||
it('does not disconnect after subsequent SIGQUITS', function() { | ||
master({}); | ||
process.emit('SIGQUIT'); | ||
cluster.disconnect.reset(); | ||
process.emit('SIGQUIT'); | ||
expect(cluster.disconnect).not.toHaveBeenCalled(); | ||
}); | ||
it('logs the SIGQUIT disconnect', function() { | ||
@@ -112,0 +165,0 @@ cluster.disconnect.andCallFake(function (cb) { |
@@ -1,3 +0,1 @@ | ||
process.setMaxListeners(0); | ||
beforeEach(function() { | ||
@@ -9,2 +7,3 @@ process.kill = jasmine.createSpy(); | ||
process.kill.reset(); | ||
process.removeAllListeners(); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
17415
411
1