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:
parent
7df8eb1050
commit
dc6d0e681c
|
@ -22,6 +22,7 @@ function Node(config) {
|
||||||
this.network = null;
|
this.network = null;
|
||||||
this.services = {};
|
this.services = {};
|
||||||
this._unloadedServices = [];
|
this._unloadedServices = [];
|
||||||
|
this._loadingServices = {};
|
||||||
|
|
||||||
// TODO type check the arguments of config.services
|
// TODO type check the arguments of config.services
|
||||||
if (config.services) {
|
if (config.services) {
|
||||||
|
@ -140,6 +141,7 @@ Node.prototype._startService = function(serviceInfo, callback) {
|
||||||
config.node = this;
|
config.node = this;
|
||||||
config.name = serviceInfo.name;
|
config.name = serviceInfo.name;
|
||||||
var service = new serviceInfo.module(config);
|
var service = new serviceInfo.module(config);
|
||||||
|
self._loadingServices[service.name] = service;
|
||||||
|
|
||||||
service.start(function(err) {
|
service.start(function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -206,9 +208,9 @@ Node.prototype.stop = function(callback) {
|
||||||
async.eachSeries(
|
async.eachSeries(
|
||||||
services,
|
services,
|
||||||
function(service, next) {
|
function(service, next) {
|
||||||
if (self.services[service.name]) {
|
if (self._loadingServices[service.name]) {
|
||||||
log.info('Stopping ' + service.name);
|
log.info('Stopping ' + service.name);
|
||||||
self.services[service.name].stop(next);
|
self._loadingServices[service.name].stop(next);
|
||||||
} else {
|
} else {
|
||||||
log.info('Stopping ' + service.name + ' (not started)');
|
log.info('Stopping ' + service.name + ' (not started)');
|
||||||
setImmediate(next);
|
setImmediate(next);
|
||||||
|
|
|
@ -333,8 +333,10 @@ describe('Bitcore Node', function() {
|
||||||
['getData', this, this.getData, 1]
|
['getData', this, this.getData, 1]
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
var testService = new TestService({node: node});
|
||||||
|
node._loadingServices = {'test1': testService};
|
||||||
node.services = {
|
node.services = {
|
||||||
'test1': new TestService({node: node})
|
'test1': testService
|
||||||
};
|
};
|
||||||
node.test2 = {};
|
node.test2 = {};
|
||||||
node.test2.stop = sinon.stub().callsArg(0);
|
node.test2.stop = sinon.stub().callsArg(0);
|
||||||
|
|
Loading…
Reference in New Issue