From cc4dd23c83476adf3caa192acba041ff000f8823 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 21 Dec 2016 15:04:43 -0800 Subject: [PATCH] pool: fix potential infinite loop with addrman. --- lib/net/pool.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/net/pool.js b/lib/net/pool.js index 21c371ae..43e4f7ec 100644 --- a/lib/net/pool.js +++ b/lib/net/pool.js @@ -2337,24 +2337,27 @@ HostList.prototype.isBanned = function isBanned(host) { }; /** - * Allocate a new loader host. + * Allocate a new host. * @returns {HostEntry} */ HostList.prototype.getHost = function getHost() { var now = this.network.now(); - var buckets = this.fresh; + var buckets = null; var factor = 1; var index, key, bucket, entry, num; - if (this.size() === 0) - return; + if (this.totalFresh > 0) + buckets = this.fresh; if (this.totalUsed > 0) { if (this.totalFresh === 0 || util.random(0, 2) === 0) buckets = this.used; } + if (!buckets) + return; + for (;;) { index = util.random(0, buckets.length); bucket = buckets[index];