Skip to content

fix critical bug that can cause up master to crash, and make use of this.reloading to ignore reload signal while reloading #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion bin/up
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ program
, 'development' == process.env.NODE_ENV ? 1 : cpus)
.option('-t, --timeout [ms]', 'Worker timeout.')
.option('-k, --keepalive', 'Restart failed workers.')
.option('-m, --manual-ready', 'Manual call require("up").ready() in code.')

/**
* Capture requires.
Expand Down Expand Up @@ -149,7 +150,8 @@ var keepAlive = program.keepalive;
*/

debug('starting cluster with %d workers on port %d', numWorkers, port);
debug('`\033[97mkill -s SIGUSR2 %d\033[90m` or \033[97mctrl + r\033[90m'
debug('`\033[97mkill -s SIGUSR2 %d\033[90m` or'
+ '`\033[97mkill -s SIGHUP %d\033[90m` or \033[97mctrl + r\033[90m'
+ ' to load new code', process.pid);

var httpServer = http.Server().listen(program.port)
Expand All @@ -159,6 +161,7 @@ var httpServer = http.Server().listen(program.port)
, requires: requires
, title: program.title
, keepAlive: keepAlive
, assumeReady: !program.manualReady
})

/**
Expand All @@ -172,6 +175,15 @@ if (program.pidfile) {
});
}

/**
* Listen on SIGHUP signal.
*/

process.on('SIGHUP', function () {
debug('\033[97mSIGHUP\033[90m signal detected - reloading');
srv.reload();
});

/**
* Listen on SIGUSR2 signal.
*/
Expand Down
8 changes: 2 additions & 6 deletions lib/up.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,10 @@ UpServer.prototype.__proto__ = Distributor.prototype;
*/

UpServer.prototype.reload = function (fn) {
if (this.reloading) {
debug('reloading in process - ignoring reload');
return this;
}

// remove all workers in the spawning state
for (var i = 0, l = this.spawning.length; i < l; i++) {
this.spawning[i].shutdown();
while (this.spawning.length > 0) {
this.spawning[0].shutdown();
}

if (this.workerTimeout > 0) {
Expand Down
2 changes: 1 addition & 1 deletion lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ process.on('message', function (msg) {
switch (msg.type) {
case 'die':
setTimeout(function () {
process.exit(0);
process.kill(process.pid);
}, msg.time);
break;
case 'ready':
Expand Down
59 changes: 35 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
{
"name": "up"
, "description": "Zero downtime reloads for Node HTTP(S) servers."
, "tags": ["cluster", "reload", "process", "monitor", "graceful", "restart"]
, "homepage": "https://github.com/learnboost/up"
, "version": "0.2.1"
, "bin": { "up": "./bin/up" }
, "main": "./lib/up"
, "engines": { "node": ">= 0.6.0" }
, "dependencies": {
"eq": "0.1.0"
, "ms": "0.1.0"
, "debug": "0.1.0"
, "commander": "0.6.1"
, "distribute": "0.1.4"
}
, "devDependencies": {
"mocha": "*"
, "expect.js": "*"
, "express": "*"
, "superagent": "*"
}
, "scripts": {
"test": "./node_modules/mocha/bin/mocha test/*.test.js"
}
"name": "up",
"description": "Zero downtime reloads for Node HTTP(S) servers.",
"tags": [
"cluster",
"reload",
"process",
"monitor",
"graceful",
"restart"
],
"homepage": "https://github.com/learnboost/up",
"version": "0.2.5",
"bin": {
"up": "./bin/up"
},
"main": "./lib/up",
"engines": {
"node": ">= 0.6.0"
},
"dependencies": {
"eq": "0.1.0",
"ms": "0.1.0",
"debug": "0.1.0",
"commander": "0.6.1",
"distribute": "0.1.4"
},
"devDependencies": {
"mocha": "*",
"expect.js": "*",
"express": "*",
"superagent": "*"
},
"scripts": {
"test": "./node_modules/mocha/bin/mocha test/*.test.js"
}
}