pool: rediscover seeds when no hosts are available.

This commit is contained in:
Christopher Jeffrey 2016-12-19 07:11:09 -08:00
parent 10e9ab9322
commit 291c7f72fe
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -114,6 +114,7 @@ function Pool(options) {
this.uid = 0;
this.createServer = null;
this.locker = new Locker();
this.dnsLock = new Locker();
this.proxyServer = null;
this.auth = null;
this.identityKey = null;
@ -1539,16 +1540,40 @@ Pool.prototype.addOutbound = function addOutbound() {
* @private
*/
Pool.prototype.fillPeers = function fillPeers() {
Pool.prototype.fillPeers = co(function* fillPeers() {
var unlock = yield this.dnsLock.lock();
try {
return yield this._fillPeers();
} finally {
unlock();
}
});
/**
* Attempt to refill the pool with peers (no lock).
* @private
*/
Pool.prototype._fillPeers = co(function* fillPeers() {
var need = this.maxOutbound - this.peers.outbound;
var i;
if (need <= 0)
return;
this.logger.debug('Refilling peers (%d/%d).',
this.peers.outbound,
this.maxOutbound);
for (i = 0; i < this.maxOutbound - 1; i++)
if (this.hosts.size() < need) {
this.logger.warning('Very few hosts available.');
this.logger.warning('Hitting DNS seeds again.');
yield this.hosts.discover(this.maxOutbound * 4);
}
for (i = 0; i < need; i++)
this.addOutbound();
};
});
/**
* Remove a peer from any list. Drop all load requests.
@ -2316,15 +2341,18 @@ HostList.prototype.addSeed = function addSeed(hostname) {
* @returns {Promise}
*/
HostList.prototype.discover = co(function* discover() {
HostList.prototype.discover = co(function* discover(total) {
var i, seed;
if (!total)
total = 16;
for (i = 0; i < this.seeds.length; i++) {
seed = this.seeds[i];
yield this.populate(seed);
if (this.list.size >= this.maxOutbound * 2)
if (this.list.size >= total)
break;
}
});