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

orca: fix race when calling listeners coincides with updating the run goroutine #6258

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions orca/producer.go
Expand Up @@ -44,7 +44,9 @@ func (*producerBuilder) Build(cci interface{}) (balancer.Producer, func()) {
listeners: make(map[OOBListener]struct{}),
backoff: internal.DefaultBackoffFunc,
}
return p, func() {}
return p, func() {
<-p.stopped
}
}

var producerBuilderSingleton = &producerBuilder{}
Expand Down Expand Up @@ -153,20 +155,19 @@ func (p *producer) recomputeMinInterval() {
func (p *producer) updateRunLocked() {
if p.stop != nil {
p.stop()
<-p.stopped
p.stop = nil
}
if len(p.listeners) > 0 {
var ctx context.Context
ctx, p.stop = context.WithCancel(context.Background())
p.stopped = make(chan struct{})
go p.run(ctx, p.minInterval)
go p.run(ctx, p.stopped, p.minInterval)
}
}

// run manages the ORCA OOB stream on the subchannel.
func (p *producer) run(ctx context.Context, interval time.Duration) {
defer close(p.stopped)
func (p *producer) run(ctx context.Context, done chan struct{}, interval time.Duration) {
defer close(done)

backoffAttempt := 0
backoffTimer := time.NewTimer(0)
Expand Down