Skip to content

Commit 2db7148

Browse files
Giulio2002claude
andauthored
[SharovBot] Fix data race between buildFiles and recalcVisibleFiles (#19590)
**[SharovBot]** Fix DATA RACE in `db/state/aggregator.go` ## Summary - `buildFiles()` calls `BeginFilesRo()` on `Domain` and `InvertedIndex` without holding `visibleFilesLock`, racing with `recalcVisibleFiles()` which writes `_visible`/`_visibleFiles` fields under the same lock - Wraps the `BeginFilesRo()` calls in `buildFiles()` with `a.visibleFilesLock.RLock()`/`RUnlock()` to synchronize with the writer, matching the pattern already used in `Aggregator.BeginFilesRo()` ## Test plan - [x] `go build ./...` passes - [x] `go test -race ./execution/verify/... -run TestHistoryVerification_WithUserTransactions` passes 3 consecutive times with no DATA RACE - [x] `go test -race ./db/state/...` passes with no DATA RACE 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e14bb2e commit 2db7148

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

db/state/aggregator.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -768,15 +768,17 @@ func (a *Aggregator) buildFiles(ctx context.Context, step kv.Step) error {
768768

769769
g, ctx := errgroup.WithContext(ctx)
770770
g.SetLimit(a.collateAndBuildWorkers)
771-
for _, d := range a.d {
771+
772+
// Use agg.BeginFilesRo() to safely snapshot visible files under visibleFilesLock,
773+
// instead of calling individual domain/ii BeginFilesRo() without synchronization.
774+
ac := a.BeginFilesRo()
775+
for id, d := range a.d {
772776
if d.Disable {
773777
continue
774778
}
775779

776780
d := d
777-
dc := d.BeginFilesRo()
778-
firstStepNotInFiles := dc.FirstStepNotInFiles()
779-
dc.Close()
781+
firstStepNotInFiles := ac.d[id].FirstStepNotInFiles()
780782
if step < firstStepNotInFiles {
781783
continue
782784
}
@@ -820,9 +822,7 @@ func (a *Aggregator) buildFiles(ctx context.Context, step kv.Step) error {
820822
}
821823

822824
ii := ii
823-
dc := ii.BeginFilesRo()
824-
firstStepNotInFiles := dc.FirstStepNotInFiles()
825-
dc.Close()
825+
firstStepNotInFiles := ac.iis[iikey].FirstStepNotInFiles()
826826
if step < firstStepNotInFiles {
827827
continue
828828
}
@@ -849,6 +849,7 @@ func (a *Aggregator) buildFiles(ctx context.Context, step kv.Step) error {
849849
return nil
850850
})
851851
}
852+
ac.Close()
852853
if err := g.Wait(); err != nil {
853854
static.CleanupOnError()
854855
return fmt.Errorf("domain collate-build: %w", err)

0 commit comments

Comments
 (0)