handle signals and stop correctly

This commit is contained in:
Patrick Nagurny 2015-08-21 15:39:46 -04:00
parent 164a2cad75
commit b0ab45f3f7
3 changed files with 16 additions and 26 deletions

View File

@ -146,8 +146,6 @@ node.on('stopping', function() {
clearInterval(interval);
});
process.stdin.resume();//so the program will not close instantly
function exitHandler(options, err) {
if (err) {
log.error('uncaught exception:', err);
@ -157,7 +155,6 @@ function exitHandler(options, err) {
process.exit(-1);
}
if (options.sigint) {
log.info('Stopping Services');
node.stop(function(err) {
if(err) {
log.error('Failed to stop services: ' + err);
@ -170,21 +167,10 @@ function exitHandler(options, err) {
}
}
//catches ctrl+c event
process.on('SIGINT', exitHandler.bind(null, {sigint:true}));
/*setTimeout(function() {
log.info('Stopping Services');
node.stop(function(err) {
if(err) {
log.error('Failed to stop services: ' + err);
return process.exit(1);
}
log.info('Halted');
process.exit(0);
});
}, 10000);*/
//catches uncaught exceptions
process.on('uncaughtException', exitHandler.bind(null, {exit:true}));
//catches ctrl+c event
process.on('exit', exitHandler.bind(null, {exit: true}));
process.on('SIGINT', exitHandler.bind(null, {sigint:true}));

View File

@ -400,10 +400,12 @@ Node.prototype._initialize = function() {
// Notify that there is a new tip
this.bitcoind.on('tip', function(height) {
var percentage = self.bitcoind.syncPercentage();
log.info('Bitcoin Core Daemon New Height:', height, 'Percentage:', percentage);
self.bitcoindHeight = height;
self._syncBitcoind();
if(!self.stopping) {
var percentage = self.bitcoind.syncPercentage();
log.info('Bitcoin Core Daemon New Height:', height, 'Percentage:', percentage);
self.bitcoindHeight = height;
self._syncBitcoind();
}
});
this.bitcoind.on('error', function(err) {
@ -478,7 +480,7 @@ Node.prototype.start = function(callback) {
};
Node.prototype.stop = function(callback) {
log.info('Stopping Bitcore Node');
log.info('Beginning shutdown');
var self = this;
var services = this.getServiceOrder().reverse();

View File

@ -104,6 +104,8 @@ static bool g_testnet = false;
static bool g_regtest = false;
static bool g_txindex = false;
static boost::thread_group threadGroup;
/**
* Private Structs
* Used for async functions and necessary linked lists at points.
@ -685,7 +687,6 @@ start_node(void) {
static void
start_node_thread(void) {
boost::thread_group threadGroup;
CScheduler scheduler;
// Workaround for AppInit2() arg parsing. Not ideal, but it works.
@ -798,7 +799,6 @@ start_node_thread(void) {
*/
NAN_METHOD(StopBitcoind) {
fprintf(stderr, "Stopping Bitcoind please wait!\n");
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
@ -840,7 +840,9 @@ NAN_METHOD(StopBitcoind) {
static void
async_stop_node(uv_work_t *req) {
async_node_data *data = static_cast<async_node_data*>(req->data);
StartShutdown();
while(!shutdown_complete) {
usleep(1E6);
}