bitcoind: handle empty input from pid file

This commit is contained in:
Braydon Fuller 2016-04-28 16:19:33 -04:00
parent 2e912af9b4
commit b0290899ce
2 changed files with 42 additions and 0 deletions

View File

@ -643,6 +643,10 @@ Bitcoin.prototype._stopSpawnedBitcoin = function(callback) {
return callback(err);
}
pid = parseInt(pid);
if (!Number.isFinite(pid)) {
// pid doesn't exist we can continue
return callback(null);
}
try {
log.warn('Stopping existing spawned bitcoin process with pid: ' + pid);
self._process.kill(pid, 'SIGINT');

View File

@ -1059,6 +1059,44 @@ describe('Bitcoin Service', function() {
done();
});
});
it('it will attempt to kill process with NaN', function(done) {
var readFile = sandbox.stub();
readFile.onCall(0).callsArgWith(2, null, ' ');
var TestBitcoinService = proxyquire('../../lib/services/bitcoind', {
fs: {
readFile: readFile
}
});
var bitcoind = new TestBitcoinService(baseConfig);
bitcoind.spawnStopTime = 1;
bitcoind._process = {};
bitcoind._process.kill = sinon.stub();
bitcoind._stopSpawnedBitcoin(function(err) {
if (err) {
return done(err);
}
done();
});
});
it('it will attempt to kill process without pid', function(done) {
var readFile = sandbox.stub();
readFile.onCall(0).callsArgWith(2, null, '');
var TestBitcoinService = proxyquire('../../lib/services/bitcoind', {
fs: {
readFile: readFile
}
});
var bitcoind = new TestBitcoinService(baseConfig);
bitcoind.spawnStopTime = 1;
bitcoind._process = {};
bitcoind._process.kill = sinon.stub();
bitcoind._stopSpawnedBitcoin(function(err) {
if (err) {
return done(err);
}
done();
});
});
});
describe('#_spawnChildProcess', function() {