bitcoind: stop failsafe timeout
This commit is contained in:
parent
2015514e78
commit
587602d080
@ -49,6 +49,7 @@ function Bitcoin(options) {
|
||||
|
||||
// limits
|
||||
this.maxAddressesQuery = options.maxAddressesQuery || Bitcoin.DEFAULT_MAX_ADDRESSES_QUERY;
|
||||
this.shutdownTimeout = options.shutdownTimeout || Bitcoin.DEFAULT_SHUTDOWN_TIMEOUT;
|
||||
|
||||
// try all interval
|
||||
this.tryAllInterval = options.tryAllInterval || Bitcoin.DEFAULT_TRY_ALL_INTERVAL;
|
||||
@ -61,6 +62,7 @@ util.inherits(Bitcoin, Service);
|
||||
|
||||
Bitcoin.dependencies = [];
|
||||
|
||||
Bitcoin.DEFAULT_SHUTDOWN_TIMEOUT = 15000;
|
||||
Bitcoin.DEFAULT_MAX_ADDRESSES_QUERY = 10000;
|
||||
Bitcoin.DEFAULT_TRY_ALL_INTERVAL = 1000;
|
||||
Bitcoin.DEFAULT_REINDEX_INTERVAL = 10000;
|
||||
@ -1570,16 +1572,26 @@ Bitcoin.prototype.generateBlock = function(num, callback) {
|
||||
*/
|
||||
Bitcoin.prototype.stop = function(callback) {
|
||||
if (this.spawn && this.spawn.process) {
|
||||
var exited = false;
|
||||
this.spawn.process.once('exit', function(code) {
|
||||
if (code !== 0) {
|
||||
var error = new Error('bitcoind spawned process exited with status code: ' + code);
|
||||
error.code = code;
|
||||
return callback(error);
|
||||
} else {
|
||||
return callback();
|
||||
if (!exited) {
|
||||
exited = true;
|
||||
if (code !== 0) {
|
||||
var error = new Error('bitcoind spawned process exited with status code: ' + code);
|
||||
error.code = code;
|
||||
return callback(error);
|
||||
} else {
|
||||
return callback();
|
||||
}
|
||||
}
|
||||
});
|
||||
this.spawn.process.kill('SIGINT');
|
||||
setTimeout(function() {
|
||||
if (!exited) {
|
||||
exited = true;
|
||||
return callback(new Error('bitcoind process did not exit'));
|
||||
}
|
||||
}, this.shutdownTimeout).unref();
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
|
||||
@ -3032,6 +3032,19 @@ describe('Bitcoin Service', function() {
|
||||
bitcoind.spawn.process.kill.args[0][0].should.equal('SIGINT');
|
||||
bitcoind.spawn.process.emit('exit', 1);
|
||||
});
|
||||
it('will stop after timeout', function(done) {
|
||||
var bitcoind = new BitcoinService(baseConfig);
|
||||
bitcoind.shutdownTimeout = 300;
|
||||
bitcoind.spawn = {};
|
||||
bitcoind.spawn.process = new EventEmitter();
|
||||
bitcoind.spawn.process.kill = sinon.stub();
|
||||
bitcoind.stop(function(err) {
|
||||
err.should.be.instanceof(Error);
|
||||
done();
|
||||
});
|
||||
bitcoind.spawn.process.kill.callCount.should.equal(1);
|
||||
bitcoind.spawn.process.kill.args[0][0].should.equal('SIGINT');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user