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