Skip to content

Commit

Permalink
storage: fix race when draining rangefeed channel
Browse files Browse the repository at this point in the history
The previous pattern used to drain a channel

    if len(ch) > 0 {
        <-ch
    }

is considered a race by the race detector if close(ch) occurs at the
same time. Adjust the channel-draining code to be race-safe by instead
perfomring repeated nonblocking reads.

Fix #30159.

Release note: None
  • Loading branch information
benesch committed Sep 13, 2018
1 parent 508a8ab commit ba87a77
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/storage/store.go
Expand Up @@ -1748,8 +1748,16 @@ func (s *Store) startClosedTimestampRangefeedSubscriber(ctx context.Context) {
select {
case <-ch:
// Drain all notifications from the channel.
for len(ch) > 0 {
<-ch
loop:
for {
select {
case _, ok := <-ch:
if !ok {
break loop
}
default:
break loop
}
}

// Gather replicas to notify under lock.
Expand Down

0 comments on commit ba87a77

Please sign in to comment.