pool: graceful disconnect - simpler approach
This commit is contained in:
parent
de36d64d4a
commit
06d25a9007
@ -352,9 +352,10 @@ Pool.prototype._disconnect = co(function* disconnect() {
|
|||||||
item.resolve();
|
item.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.peers.destroy();
|
// prevent peer list from trying to refill
|
||||||
|
this.disconnecting = true;
|
||||||
|
|
||||||
this.nonces = new NonceList();
|
this.peers.destroy();
|
||||||
|
|
||||||
this.requestMap.reset();
|
this.requestMap.reset();
|
||||||
|
|
||||||
@ -376,6 +377,7 @@ Pool.prototype._disconnect = co(function* disconnect() {
|
|||||||
|
|
||||||
yield this.unlisten();
|
yield this.unlisten();
|
||||||
|
|
||||||
|
this.disconnecting = false;
|
||||||
this.syncing = false;
|
this.syncing = false;
|
||||||
this.connected = false;
|
this.connected = false;
|
||||||
});
|
});
|
||||||
@ -1154,7 +1156,8 @@ Pool.prototype.handleClose = co(function* handleClose(peer, connected) {
|
|||||||
if (!outbound)
|
if (!outbound)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.refill();
|
if(!this.disconnecting)
|
||||||
|
this.refill();
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -3722,22 +3725,10 @@ PeerList.prototype.has = function has(hostname) {
|
|||||||
PeerList.prototype.destroy = function destroy() {
|
PeerList.prototype.destroy = function destroy() {
|
||||||
var peer, next;
|
var peer, next;
|
||||||
|
|
||||||
this.map = {};
|
|
||||||
this.load = null;
|
|
||||||
this.inbound = 0;
|
|
||||||
this.outbound = 0;
|
|
||||||
|
|
||||||
for (peer = this.list.head; peer; peer = next) {
|
for (peer = this.list.head; peer; peer = next) {
|
||||||
next = peer.next;
|
next = peer.next;
|
||||||
|
|
||||||
// stop processing peer events
|
|
||||||
peer.onPacket = null;
|
|
||||||
peer.removeAllListeners()
|
|
||||||
|
|
||||||
peer.destroy();
|
peer.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.list = new List();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user