Skip to content

Commit

Permalink
fix instance chooser (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
binbin0325 authored May 31, 2021
1 parent 7a2d20f commit fb49039
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 3 additions & 0 deletions clients/naming_client/naming_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions clients/naming_client/naming_instance_chooser.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package naming_client
import (
"math/rand"
"sort"
"time"

"github.com/nacos-group/nacos-sdk-go/model"
)
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit fb49039

Please sign in to comment.