pool: fix finalization
This commit is contained in:
parent
3ef7008a32
commit
6d99072caf
@ -90,6 +90,8 @@ Peer.prototype._init = function init() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Peer.prototype.broadcast = function broadcast(items) {
|
Peer.prototype.broadcast = function broadcast(items) {
|
||||||
|
if (this.destroyed)
|
||||||
|
return;
|
||||||
if (!Array.isArray(items))
|
if (!Array.isArray(items))
|
||||||
items = [ items ];
|
items = [ items ];
|
||||||
|
|
||||||
@ -185,6 +187,9 @@ Peer.prototype._error = function error(err) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Peer.prototype._req = function _req(cmd, cb) {
|
Peer.prototype._req = function _req(cmd, cb) {
|
||||||
|
if (this.destroyed)
|
||||||
|
return cb(new Error('Destroyed, sorry'));
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
var entry = {
|
var entry = {
|
||||||
cmd: cmd,
|
cmd: cmd,
|
||||||
@ -216,7 +221,8 @@ Peer.prototype._res = function _res(cmd, payload) {
|
|||||||
assert(!entry.cmd);
|
assert(!entry.cmd);
|
||||||
|
|
||||||
// Restart timer
|
// Restart timer
|
||||||
entry.timer = setTimeout(entry.ontimeout, this._request.timeout);
|
if (!this.destroyed)
|
||||||
|
entry.timer = setTimeout(entry.ontimeout, this._request.timeout);
|
||||||
return true;
|
return true;
|
||||||
} else if (res !== this._request.skip) {
|
} else if (res !== this._request.skip) {
|
||||||
this._request.queue.shift();
|
this._request.queue.shift();
|
||||||
|
|||||||
@ -130,7 +130,6 @@ Pool.prototype._addLoader = function _addLoader() {
|
|||||||
// Chain is full and up-to-date
|
// Chain is full and up-to-date
|
||||||
if (self.chain.isFull()) {
|
if (self.chain.isFull()) {
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
self._removePeer(peer);
|
|
||||||
self.emit('full');
|
self.emit('full');
|
||||||
self.block.lastHash = null;
|
self.block.lastHash = null;
|
||||||
return;
|
return;
|
||||||
@ -453,6 +452,8 @@ Pool.prototype._response = function _response(entity) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Pool.prototype._scheduleRequests = function _scheduleRequests() {
|
Pool.prototype._scheduleRequests = function _scheduleRequests() {
|
||||||
|
if (this.destroyed)
|
||||||
|
return;
|
||||||
if (this.request.active > this.parallel / 2)
|
if (this.request.active > this.parallel / 2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -605,12 +606,19 @@ Pool.prototype.destroy = function destroy() {
|
|||||||
this.request.queue.slice().forEach(function(item) {
|
this.request.queue.slice().forEach(function(item) {
|
||||||
item.finish(null);
|
item.finish(null);
|
||||||
});
|
});
|
||||||
|
this.tx.list.forEach(function(tx) {
|
||||||
|
clearTimeout(tx.timer);
|
||||||
|
tx.timer = null;
|
||||||
|
});
|
||||||
this.peers.pending.slice().forEach(function(peer) {
|
this.peers.pending.slice().forEach(function(peer) {
|
||||||
peer.destroy();
|
peer.destroy();
|
||||||
});
|
});
|
||||||
this.peers.block.slice().forEach(function(peer) {
|
this.peers.block.slice().forEach(function(peer) {
|
||||||
peer.destroy();
|
peer.destroy();
|
||||||
});
|
});
|
||||||
|
if (this.load.timer)
|
||||||
|
clearTimeout(this.load.timer);
|
||||||
|
this.load.timer = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
Pool.prototype.toJSON = function toJSON() {
|
Pool.prototype.toJSON = function toJSON() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user