bitcoind: stop failsafe timeout
This commit is contained in:
parent
2015514e78
commit
587602d080
@ -49,6 +49,7 @@ function Bitcoin(options) {
|
|||||||
|
|
||||||
// limits
|
// limits
|
||||||
this.maxAddressesQuery = options.maxAddressesQuery || Bitcoin.DEFAULT_MAX_ADDRESSES_QUERY;
|
this.maxAddressesQuery = options.maxAddressesQuery || Bitcoin.DEFAULT_MAX_ADDRESSES_QUERY;
|
||||||
|
this.shutdownTimeout = options.shutdownTimeout || Bitcoin.DEFAULT_SHUTDOWN_TIMEOUT;
|
||||||
|
|
||||||
// try all interval
|
// try all interval
|
||||||
this.tryAllInterval = options.tryAllInterval || Bitcoin.DEFAULT_TRY_ALL_INTERVAL;
|
this.tryAllInterval = options.tryAllInterval || Bitcoin.DEFAULT_TRY_ALL_INTERVAL;
|
||||||
@ -61,6 +62,7 @@ util.inherits(Bitcoin, Service);
|
|||||||
|
|
||||||
Bitcoin.dependencies = [];
|
Bitcoin.dependencies = [];
|
||||||
|
|
||||||
|
Bitcoin.DEFAULT_SHUTDOWN_TIMEOUT = 15000;
|
||||||
Bitcoin.DEFAULT_MAX_ADDRESSES_QUERY = 10000;
|
Bitcoin.DEFAULT_MAX_ADDRESSES_QUERY = 10000;
|
||||||
Bitcoin.DEFAULT_TRY_ALL_INTERVAL = 1000;
|
Bitcoin.DEFAULT_TRY_ALL_INTERVAL = 1000;
|
||||||
Bitcoin.DEFAULT_REINDEX_INTERVAL = 10000;
|
Bitcoin.DEFAULT_REINDEX_INTERVAL = 10000;
|
||||||
@ -1570,16 +1572,26 @@ Bitcoin.prototype.generateBlock = function(num, callback) {
|
|||||||
*/
|
*/
|
||||||
Bitcoin.prototype.stop = function(callback) {
|
Bitcoin.prototype.stop = function(callback) {
|
||||||
if (this.spawn && this.spawn.process) {
|
if (this.spawn && this.spawn.process) {
|
||||||
|
var exited = false;
|
||||||
this.spawn.process.once('exit', function(code) {
|
this.spawn.process.once('exit', function(code) {
|
||||||
if (code !== 0) {
|
if (!exited) {
|
||||||
var error = new Error('bitcoind spawned process exited with status code: ' + code);
|
exited = true;
|
||||||
error.code = code;
|
if (code !== 0) {
|
||||||
return callback(error);
|
var error = new Error('bitcoind spawned process exited with status code: ' + code);
|
||||||
} else {
|
error.code = code;
|
||||||
return callback();
|
return callback(error);
|
||||||
|
} else {
|
||||||
|
return callback();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.spawn.process.kill('SIGINT');
|
this.spawn.process.kill('SIGINT');
|
||||||
|
setTimeout(function() {
|
||||||
|
if (!exited) {
|
||||||
|
exited = true;
|
||||||
|
return callback(new Error('bitcoind process did not exit'));
|
||||||
|
}
|
||||||
|
}, this.shutdownTimeout).unref();
|
||||||
} else {
|
} else {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3032,6 +3032,19 @@ describe('Bitcoin Service', function() {
|
|||||||
bitcoind.spawn.process.kill.args[0][0].should.equal('SIGINT');
|
bitcoind.spawn.process.kill.args[0][0].should.equal('SIGINT');
|
||||||
bitcoind.spawn.process.emit('exit', 1);
|
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