Skip to content

Commit 185bee5

Browse files
Giulio2002claude
andcommitted
db/state: fix data race between buildFiles and recalcVisibleFiles
buildFiles() calls BeginFilesRo() on Domain and InvertedIndex without holding visibleFilesLock, racing with recalcVisibleFiles() which writes _visible/_visibleFiles under the same lock. Wrap the BeginFilesRo() calls in buildFiles() with visibleFilesLock.RLock() to synchronize with the writer, matching the pattern already used in Aggregator.BeginFilesRo(). Fixes TestHistoryVerification_WithUserTransactions DATA RACE. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent 8d4b28d commit 185bee5

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

db/state/aggregator.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,10 @@ func (a *Aggregator) buildFiles(ctx context.Context, step kv.Step) error {
687687

688688
g, ctx := errgroup.WithContext(ctx)
689689
g.SetLimit(a.collateAndBuildWorkers)
690+
691+
// Acquire read lock to protect BeginFilesRo() calls from concurrent writes
692+
// by recalcVisibleFiles() in BuildMissedAccessorsInBackground.
693+
a.visibleFilesLock.RLock()
690694
for _, d := range a.d {
691695
if d.Disable {
692696
continue
@@ -768,6 +772,7 @@ func (a *Aggregator) buildFiles(ctx context.Context, step kv.Step) error {
768772
return nil
769773
})
770774
}
775+
a.visibleFilesLock.RUnlock()
771776
if err := g.Wait(); err != nil {
772777
static.CleanupOnError()
773778
return fmt.Errorf("domain collate-build: %w", err)

0 commit comments

Comments
 (0)