diff --git a/storage/reads/reader.go b/storage/reads/reader.go index 60ea9374b0..e0651188cb 100644 --- a/storage/reads/reader.go +++ b/storage/reads/reader.go @@ -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 }