Rework connection artifacts choice logic

Signed-off-by: Pavel Korotkov <pavel@nspcc.ru>
This commit is contained in:
Pavel Korotkov 2021-04-08 12:37:55 +03:00 committed by Pavel Korotkov
parent fad05b76d4
commit e3dbecf844

View file

@ -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_
}
}
if i != nil {
cp := p.clientPacks[*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
}
}
return nil, nil, errors.New("no healthy client")
}