mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-14 02:07:59 -07:00
Better randomize solicited Gateway URLs
Shuffle the array created when iterating through the gateways URLs map since map iteration may not be well randomized with small maps. Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
This commit is contained in:
@@ -1304,6 +1304,10 @@ func (g *gatewayCfg) getURLs() []*url.URL {
|
||||
a = append(a, u)
|
||||
}
|
||||
g.RUnlock()
|
||||
// Map iteration is random, but not that good with small maps.
|
||||
rand.Shuffle(len(a), func(i, j int) {
|
||||
a[i], a[j] = a[j], a[i]
|
||||
})
|
||||
return a
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user