Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

clusterflock

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clusterflock - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

46

lib/master.js

@@ -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();
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc