fix shutdown loop.
This commit is contained in:
parent
3aacd0a089
commit
7f7ef196f4
@ -30,6 +30,10 @@ Bitcoin.prototype.__proto__ = EventEmitter.prototype;
|
|||||||
Bitcoin.prototype.start = function(callback) {
|
Bitcoin.prototype.start = function(callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
var none = {};
|
||||||
|
var exitCaught = none;
|
||||||
|
var errorCaught = none;
|
||||||
|
|
||||||
this.log_pipe = bitcoindjs.start(function(err, status) {
|
this.log_pipe = bitcoindjs.start(function(err, status) {
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(err);
|
callback(err);
|
||||||
@ -42,12 +46,29 @@ Bitcoin.prototype.start = function(callback) {
|
|||||||
self.emit('open', status);
|
self.emit('open', status);
|
||||||
}
|
}
|
||||||
|
|
||||||
function stop() {
|
process.on('SIGINT', self.stop.bind(self));
|
||||||
return self.stop();
|
process.on('SIGHUP', self.stop.bind(self));
|
||||||
}
|
|
||||||
|
|
||||||
process.on('SIGINT', stop);
|
var exit = process.exit;
|
||||||
process.on('SIGHUP', stop);
|
self._exit = function() {
|
||||||
|
return exit.apply(process, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
|
process.exit = function(code) {
|
||||||
|
exitCaught = code || 0;
|
||||||
|
if (!self._shutdown) {
|
||||||
|
return self._exit(exitCaught);
|
||||||
|
}
|
||||||
|
self.stop();
|
||||||
|
};
|
||||||
|
|
||||||
|
process.on('uncaughtException', function(err) {
|
||||||
|
errorCaught = err;
|
||||||
|
if (!self._shutdown) {
|
||||||
|
return self._exit(exitCaught !== none ? exitCaught : 1);
|
||||||
|
}
|
||||||
|
self.stop();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// bitcoind's boost threads aren't in the thread pool
|
// bitcoind's boost threads aren't in the thread pool
|
||||||
@ -57,10 +78,23 @@ Bitcoin.prototype.start = function(callback) {
|
|||||||
self._stoppingSaid = true;
|
self._stoppingSaid = true;
|
||||||
self.log('shutting down...');
|
self.log('shutting down...');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bitcoindjs.stopped()) {
|
if (bitcoindjs.stopped()) {
|
||||||
self.log('shut down.');
|
self.log('shut down.');
|
||||||
|
|
||||||
clearInterval(self._shutdown);
|
clearInterval(self._shutdown);
|
||||||
delete self._shutdown;
|
delete self._shutdown;
|
||||||
|
|
||||||
|
if (exitCaught !== none) {
|
||||||
|
return self._exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorCaught !== none) {
|
||||||
|
if (errorCaught.stack) {
|
||||||
|
console.error(errorCaught.stack);
|
||||||
|
}
|
||||||
|
return self._exit(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user