Skip to content
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

Fix process not recycled properly on Windows #1727

Merged
merged 3 commits into from
Nov 2, 2015
Merged
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
19 changes: 17 additions & 2 deletions lib/God/Methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ var Common = require('../Common');
var treekill = require('../TreeKill');
var cst = require('../../constants.js');
var debug = require('debug')('god:methods');
var os = require('os');

/**
* Kill process group in a cross platform way
* @method crossPlatformGroupKill
* @param int pid
* @param string sig
*/
function crossPlatformGroupKill(pid, sig) {
// This would have not been needed if node.js were able
// to handle group process kill on Windows (pid < -1).
if (os.platform() === 'win32') treekill(pid, sig);
else process.kill(-pid, sig);
}

/**
* Description
* @method exports
Expand Down Expand Up @@ -214,7 +229,7 @@ module.exports = function(God) {
else {
console.log('Process with pid %d still alive after %sms, sending it SIGKILL now...', pid, cst.KILL_TIMEOUT);
try {
process.kill(-(parseInt(pid)), 'SIGKILL');
crossPlatformGroupKill(parseInt(pid),'SIGKILL');
} catch(e) { console.error('Process cannot be killed', e.message || e.stack || e); }
return God.processIsDead(pid, cb, true);
}
Expand Down Expand Up @@ -242,7 +257,7 @@ module.exports = function(God) {
if (mode.indexOf('cluster') === 0)
treekill(parseInt(pid));
else
process.kill(-(parseInt(pid)), 'SIGINT');
crossPlatformGroupKill(parseInt(pid), 'SIGINT');
}
} catch(e) {
console.error('%s pid can not be killed', pid, e);
Expand Down