Merge pull request #125 from mnaamani/fix-pool-graceful-disconnect

pool: graceful disconnect
This commit is contained in:
Christopher Jeffrey (JJ) 2017-01-27 00:08:19 -08:00 committed by GitHub
commit 594b39de66

View File

@ -352,6 +352,9 @@ Pool.prototype._disconnect = co(function* disconnect() {
item.resolve();
}
// prevent peer list from trying to refill
this.disconnecting = true;
this.peers.destroy();
this.requestMap.reset();
@ -374,6 +377,7 @@ Pool.prototype._disconnect = co(function* disconnect() {
yield this.unlisten();
this.disconnecting = false;
this.syncing = false;
this.connected = false;
});
@ -1152,6 +1156,9 @@ Pool.prototype.handleClose = co(function* handleClose(peer, connected) {
if (!outbound)
return;
if(this.disconnecting)
return;
this.refill();
});
@ -3720,11 +3727,6 @@ 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;
peer.destroy();