diff --git a/zk/conn.go b/zk/conn.go index da9503a2..60bd4779 100644 --- a/zk/conn.go +++ b/zk/conn.go @@ -188,7 +188,7 @@ func Connect(servers []string, sessionTimeout time.Duration, options ...connOpti } // Randomize the order of the servers to avoid creating hotspots - stringShuffle(srvs) + srvs = stringShuffle(srvs) ec := make(chan Event, eventChanSize) conn := &Conn{ diff --git a/zk/dnshostprovider.go b/zk/dnshostprovider.go index f4bba8d0..a50f71d2 100644 --- a/zk/dnshostprovider.go +++ b/zk/dnshostprovider.go @@ -50,7 +50,7 @@ func (hp *DNSHostProvider) Init(servers []string) error { } // Randomize the order of the servers to avoid creating hotspots - stringShuffle(found) + found = stringShuffle(found) hp.servers = found hp.curr = -1 diff --git a/zk/util.go b/zk/util.go index f40a5b15..e7476f45 100644 --- a/zk/util.go +++ b/zk/util.go @@ -47,11 +47,12 @@ func FormatServers(servers []string) []string { } // stringShuffle performs a Fisher-Yates shuffle on a slice of strings -func stringShuffle(s []string) { +func stringShuffle(s []string) []string { for i := len(s) - 1; i > 0; i-- { j := rand.Intn(i + 1) s[i], s[j] = s[j], s[i] } + return s } // validatePath will make sure a path is valid before sending the request