diff --git a/net/gsel/gsel_selector_round_robin.go b/net/gsel/gsel_selector_round_robin.go index fe611a6499a..5c73ca42ae3 100644 --- a/net/gsel/gsel_selector_round_robin.go +++ b/net/gsel/gsel_selector_round_robin.go @@ -14,7 +14,7 @@ import ( ) type selectorRoundRobin struct { - mu sync.RWMutex + mu sync.Mutex nodes Nodes next int } @@ -28,14 +28,15 @@ func NewSelectorRoundRobin() Selector { func (s *selectorRoundRobin) Update(ctx context.Context, nodes Nodes) error { intlog.Printf(ctx, `Update nodes: %s`, nodes.String()) s.mu.Lock() + defer s.mu.Unlock() s.nodes = nodes - s.mu.Unlock() + s.next = 0 return nil } func (s *selectorRoundRobin) Pick(ctx context.Context) (node Node, done DoneFunc, err error) { - s.mu.RLock() - defer s.mu.RUnlock() + s.mu.Lock() + defer s.mu.Unlock() node = s.nodes[s.next] s.next = (s.next + 1) % len(s.nodes) intlog.Printf(ctx, `Picked node: %s`, node.Address())