Skip to content

Instantly share code, notes, and snippets.

@alanning
Last active December 28, 2015 04:39
Show Gist options
  • Save alanning/7443935 to your computer and use it in GitHub Desktop.
Save alanning/7443935 to your computer and use it in GitHub Desktop.
rolling timeout for child processes. Test via `mrt update` on a system with `git 1.7.1` installed. `rm -rf ~/.meteorite/source/meteor` to clear local cache so clone is invoked.
GitSource.prototype._clone = function(fn) {
var self = this,
timeout = 5000,
handle,
child,
errOutput = [];
//console.log('git clone')
if (!fs.existsSync(this.sourcePath)) {
child = exec('git clone --progress ' + self.url + ' "' + this.sourcePath + '"', function(err, stdout, stderr) {
//console.log('exec cb fired')
if (err) {
console.error(errOutput.join(''))
throw "There was a problem cloning repo: " + self.url +
"\nPlease check https://github.com/oortcloud/meteorite/blob/master/CONTRIBUTING.md#troubleshooting for potential explanations.";
}
errOutput = null;
fn();
});
function rescheduleKill () {
//console.log('rescheduleKill');
if (handle) {
clearTimeout(handle)
}
handle = setTimeout(function () {
console.log('killing child process...')
child.kill('SIGHUP')
}, timeout)
}
rescheduleKill()
child.stdout.on('data', function (data) {
rescheduleKill()
//console.log('git clone stdout: ', data.toString());
});
child.stderr.on('data', function (data) {
rescheduleKill()
//console.log('git clone stderr: ', data.toString());
errOutput.push(data.toString())
});
child.on('close', function (code, signal) {
clearTimeout(handle);
if (signal) {
console.log('child process closed due to receipt of signal '+signal);
}
});
child.on('exit', function (code, signal) {
clearTimeout(handle);
if (signal) {
console.log('child process exited due to receipt of signal '+signal);
console.error('stopping meteorite due to hung git process')
console.error(errOutput.join(''))
process.exit(1)
}
});
} else {
fn();
}
};
{
"meteor": {
"tag":"release/0.6.4.1"
},
"packages": {
"testp1": {
"git":"https://github.com/meteor/meteor.git"
},
"twilio-meteor": {
"git":"http://github.com/andreioprisan/twilio-meteor.git"
}
}
}
(Notes: Rolling timeout successfully lets long clone of Meteor repo complete, while hung process for twilio-meteor is killed as hoped.)
[rack-user@sw911-a app]$ mrt update
project fetch
✓ testp1
branch: https://github.com/meteor/meteor.git#master
✓ twilio-meteor
branch: http://github.com/andreioprisan/twilio-meteor.git#master
killing child process...
child process exited due to receipt of signal SIGHUP
stopping meteorite due to hung git process
error: RPC failed; result=22, HTTP code = 405
[rack-user@sw911-a app]$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment