diff --git a/lib/services/bitcoind.js b/lib/services/bitcoind.js index 4d24d1d7..b86174ef 100644 --- a/lib/services/bitcoind.js +++ b/lib/services/bitcoind.js @@ -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'); diff --git a/test/services/bitcoind.unit.js b/test/services/bitcoind.unit.js index 1e642461..bbc88a8b 100644 --- a/test/services/bitcoind.unit.js +++ b/test/services/bitcoind.unit.js @@ -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() {