From e3dbecf8441645ad72e70e7b47d75a5e0c008ea0 Mon Sep 17 00:00:00 2001 From: Pavel Korotkov Date: Thu, 8 Apr 2021 12:37:55 +0300 Subject: [PATCH] Rework connection artifacts choice logic Signed-off-by: Pavel Korotkov --- connections/pool.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/connections/pool.go b/connections/pool.go index e705ea1..256acfa 100644 --- a/connections/pool.go +++ b/connections/pool.go @@ -128,16 +128,12 @@ func (p *pool) ConnectionArtifacts() (client.Client, *token.SessionToken, error) } return nil, nil, errors.New("no healthy client") } - var i *int = nil - for k := 0; k < 10; k++ { - i_ := p.sampler.Next() - if p.clientPacks[i_].healthy { - i = &i_ + attempts := 3 * len(p.clientPacks) + for k := 0; k < attempts; k++ { + i := p.sampler.Next() + if cp := p.clientPacks[i]; cp.healthy { + return cp.client, cp.sessionToken, nil } } - if i != nil { - cp := p.clientPacks[*i] - return cp.client, cp.sessionToken, nil - } return nil, nil, errors.New("no healthy client") }