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)
This commit is contained in:
Chris Kleeschulte 2015-09-15 14:18:18 -04:00
parent 7df8eb1050
commit dc6d0e681c
2 changed files with 7 additions and 3 deletions

View File

@ -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);

View File

@ -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);