pool: graceful disconnect - simpler approach

This commit is contained in:
Mokhtar Naamani 2017-01-27 09:56:58 +02:00
parent de36d64d4a
commit 06d25a9007

View File

@ -352,9 +352,10 @@ Pool.prototype._disconnect = co(function* disconnect() {
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();
@ -376,6 +377,7 @@ Pool.prototype._disconnect = co(function* disconnect() {
yield this.unlisten();
this.disconnecting = false;
this.syncing = false;
this.connected = false;
});
@ -1154,7 +1156,8 @@ Pool.prototype.handleClose = co(function* handleClose(peer, connected) {
if (!outbound)
return;
this.refill();
if(!this.disconnecting)
this.refill();
});
/**
@ -3722,22 +3725,10 @@ PeerList.prototype.has = function has(hostname) {
PeerList.prototype.destroy = function destroy() {
var peer, next;
this.map = {};
this.load = null;
this.inbound = 0;
this.outbound = 0;
for (peer = this.list.head; peer; peer = next) {
next = peer.next;
// stop processing peer events
peer.onPacket = null;
peer.removeAllListeners()
peer.destroy();
}
this.list = new List();
};
/**