From 83dbe4c7823227f11139f9cd91da9834f24067a3 Mon Sep 17 00:00:00 2001 From: jbhusson <jonah@elixxir.io> Date: Mon, 17 Oct 2022 18:24:28 -0400 Subject: [PATCH] Fix host pool size checking --- cmix/gateway/hostPool.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/cmix/gateway/hostPool.go b/cmix/gateway/hostPool.go index c37dbdf2f..65d5fb7c4 100644 --- a/cmix/gateway/hostPool.go +++ b/cmix/gateway/hostPool.go @@ -307,11 +307,13 @@ func (h *HostPool) initialize(startIdx uint32) error { id *id.ID latency time.Duration } + numGatewaysToTry := h.poolParams.MaxPings numGateways := uint32(len(randomGateways)) if numGatewaysToTry > numGateways { numGatewaysToTry = numGateways } + resultList := make([]gatewayDuration, 0, numGatewaysToTry) // Begin trying gateways @@ -320,12 +322,6 @@ func (h *HostPool) initialize(startIdx uint32) error { i := uint32(0) for !exit { for ; i < numGateways; i++ { - // Ran out of Hosts to try - if i >= numGateways { - exit = true - break - } - // Select a gateway not yet selected gwId, err := randomGateways[i].GetGatewayId() if err != nil { @@ -334,8 +330,6 @@ func (h *HostPool) initialize(startIdx uint32) error { // Skip if already in HostPool if _, ok := h.hostMap[*gwId]; ok { - // Try another Host instead - numGatewaysToTry++ continue } @@ -370,7 +364,7 @@ func (h *HostPool) initialize(startIdx uint32) error { } // Break if we have all needed slots - if uint32(len(resultList)) == numGatewaysToTry { + if uint32(len(resultList)) == numGatewaysToTry || i >= numGateways { exit = true timer.Stop() break innerLoop -- GitLab