fix(storage): avoid data race on table Done channel

Fixes #1021.
pull/10616/head
Mark Rushakoff 2018-10-10 21:47:40 -07:00 committed by Mark Rushakoff
parent 796ef33484
commit d479c330fe
1 changed files with 5 additions and 1 deletions

View File

@ -166,12 +166,16 @@ READ:
continue
}
// Evaluate table.Done early to avoid a data race if table.Close() is run on another goroutine
// and reassigns the underlying channel.
done := table.Done()
if err := f(table); err != nil {
table.Close()
return err
}
select {
case <-table.Done():
case <-done:
case <-bi.ctx.Done():
break READ
}