From fb490395cee60810c0df916f0a784aa97b9f6e7f Mon Sep 17 00:00:00 2001 From: "binbin.zhang" Date: Mon, 31 May 2021 09:14:44 +0800 Subject: [PATCH] fix instance chooser (#254) --- clients/naming_client/naming_client.go | 3 +++ clients/naming_client/naming_instance_chooser.go | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/clients/naming_client/naming_client.go b/clients/naming_client/naming_client.go index dd876712..5faa91b2 100644 --- a/clients/naming_client/naming_client.go +++ b/clients/naming_client/naming_client.go @@ -18,7 +18,9 @@ package naming_client import ( "math" + "math/rand" "strings" + "time" "github.com/nacos-group/nacos-sdk-go/clients/nacos_client" "github.com/nacos-group/nacos-sdk-go/clients/naming_client/naming_cache" @@ -38,6 +40,7 @@ type NamingClient struct { } func NewNamingClient(nc nacos_client.INacosClient) (*NamingClient, error) { + rand.Seed(time.Now().UnixNano()) naming := &NamingClient{INacosClient: nc} clientConfig, err := nc.GetClientConfig() if err != nil { diff --git a/clients/naming_client/naming_instance_chooser.go b/clients/naming_client/naming_instance_chooser.go index da438206..230330fc 100644 --- a/clients/naming_client/naming_instance_chooser.go +++ b/clients/naming_client/naming_instance_chooser.go @@ -19,7 +19,6 @@ package naming_client import ( "math/rand" "sort" - "time" "github.com/nacos-group/nacos-sdk-go/model" ) @@ -57,7 +56,6 @@ func newChooser(instances []model.Instance) Chooser { } func (chs Chooser) pick() model.Instance { - rand.Seed(time.Now().Unix()) r := rand.Intn(chs.max) + 1 i := sort.SearchInts(chs.totals, r) return chs.data[i]