Skip to content

Commit

Permalink
Merge pull request #8489 from planetscale/rn-vstreamer-throttler-goro…
Browse files Browse the repository at this point in the history
…utine-leak

Return from throttler goroutine if context is cancelled to prevent goroutine leaks
  • Loading branch information
rohit-nayak-ps authored Jul 17, 2021
2 parents 7c1e8ee + 96d7cd8 commit 08aa289
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions go/vt/vttablet/tabletserver/vstreamer/vstreamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,31 @@ func (vs *vstreamer) parseEvents(ctx context.Context, events <-chan mysql.Binlog
for {
// check throttler.
if !vs.vse.throttlerClient.ThrottleCheckOKOrWait(ctx) {
select {
// make sure to leave if context is cancelled
case <-ctx.Done():
return
default:
// do nothing special
}
continue
}

ev, ok := <-events
if ok {
throttledEvents <- ev
} else {
close(throttledEvents)
select {
case ev, ok := <-events:
if ok {
select {
case throttledEvents <- ev:
case <-ctx.Done():
return
}
} else {
close(throttledEvents)
return
}
case <-ctx.Done():
return
}

}
}()
for {
Expand Down

0 comments on commit 08aa289

Please sign in to comment.