From dc6d0e681c92c6d30789be73d77e77471bf3006d Mon Sep 17 00:00:00 2001 From: Chris Kleeschulte Date: Tue, 15 Sep 2015 14:18:18 -0400 Subject: [PATCH] Crash on reindex - Added the concept of loadServices on the node so that the node can conditionally call stop on loadingServices - This serves the case where services might be loading versus fully loaded (which is not always the cases for heavy services like bitcoind) --- lib/node.js | 6 ++++-- test/node.unit.js | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/node.js b/lib/node.js index 3061610c..b58356a1 100644 --- a/lib/node.js +++ b/lib/node.js @@ -22,6 +22,7 @@ function Node(config) { this.network = null; this.services = {}; this._unloadedServices = []; + this._loadingServices = {}; // TODO type check the arguments of config.services if (config.services) { @@ -140,6 +141,7 @@ Node.prototype._startService = function(serviceInfo, callback) { config.node = this; config.name = serviceInfo.name; var service = new serviceInfo.module(config); + self._loadingServices[service.name] = service; service.start(function(err) { if (err) { @@ -206,9 +208,9 @@ Node.prototype.stop = function(callback) { async.eachSeries( services, function(service, next) { - if (self.services[service.name]) { + if (self._loadingServices[service.name]) { log.info('Stopping ' + service.name); - self.services[service.name].stop(next); + self._loadingServices[service.name].stop(next); } else { log.info('Stopping ' + service.name + ' (not started)'); setImmediate(next); diff --git a/test/node.unit.js b/test/node.unit.js index 6593f7b5..d1589152 100644 --- a/test/node.unit.js +++ b/test/node.unit.js @@ -333,8 +333,10 @@ describe('Bitcore Node', function() { ['getData', this, this.getData, 1] ]; }; + var testService = new TestService({node: node}); + node._loadingServices = {'test1': testService}; node.services = { - 'test1': new TestService({node: node}) + 'test1': testService }; node.test2 = {}; node.test2.stop = sinon.stub().callsArg(0);