Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue in array border exceeded in RoundRobin of package gsel #2642

Merged
merged 2 commits into from
May 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions net/gsel/gsel_selector_round_robin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

type selectorRoundRobin struct {
mu sync.RWMutex
mu sync.Mutex
nodes Nodes
next int
}
Expand All @@ -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())
Expand Down