rpc: ensure shutdown. see #188.

This commit is contained in:
Christopher Jeffrey 2017-04-30 06:10:01 -07:00
parent a5520abaae
commit 4f09065a3e
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 14 additions and 1 deletions

View File

@ -195,10 +195,22 @@ RPC.prototype.help = co(function* _help(args, help) {
});
RPC.prototype.stop = co(function* stop(args, help) {
var self = this;
if (help || args.length !== 0)
throw new RPCError(errs.MISC_ERROR, 'stop');
this.node.close();
co(function* () {
try {
yield self.node.close();
} catch (e) {
if (process.exit)
process.exit(1);
return;
}
if (process.exit)
process.exit(0);
})();
return 'Stopping.';
});

View File

@ -537,6 +537,7 @@ Worker.prototype._initChildProcess = function _initChildProcess() {
var options = { stdio: 'pipe', env: env };
this.child = cp.spawn(file, argv, options);
this.child.unref();
this.child.on('error', function(err) {
self.emit('error', err);