[SharovBot] db/state: fix DATA RACE in closeFilesAndRemove - #21465
Closed
erigon-copilot[bot] wants to merge 1 commit into
Closed
erigon-copilot[bot] wants to merge 1 commit into
erigon-copilot[bot] wants to merge 1 commit into
Conversation
…via sync.Once The race detector caught two goroutines concurrently executing closeFilesAndRemove() on the same FilesItem through the visibleFiles.refcntDecrement() → closeFilesAndRemove() path. This was a TOCTOU in the old per-file refcount/canDelete mechanism: deleteMergeFile sets canDelete=true then checks refcount==0, while refcntDecrement decrements refcount to 0 then checks canDelete — both observe (refcount==0, canDelete==true) and both enter closeFilesAndRemove(), racing on Decompressor.Close() and other fields. The bundle-level refcount redesign (aggregatorVisible.refcnt) structurally prevents this for the main code path, but the old per-file mechanism is still used by the forkable/snap_repo subsystem. Wrapping closeFilesAndRemove in sync.Once provides defense-in-depth: even if two code paths attempt to close the same FilesItem concurrently, only one executes the destructive logic while the other blocks and returns. Fixes the DATA RACE in TestHistoryVerification_SimpleBlocks (execution/verify). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Giulio Rebuffo <giulio.rebuffo@gmail.com>
erigon-copilot
Bot
requested review from
AskAlexSharov and
sudeepdino008
as code owners
May 28, 2026 05:03
Contributor
Author
|
[SharovBot] Closing this PR as superseded by #21397, which already contains the fix. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
FilesItem.closeFilesAndRemove()by wrapping the method body withsync.Once, preventing concurrent double-close of file descriptors and mmap handlescloseFilesAndRemove()on the sameFilesItemthrough the old per-filerefcntDecrementpath (TOCTOU betweencanDeleteandrefcountatomics)aggregatorVisible.refcnt) structurally prevents this for the main code path, butsync.Onceprovides defense-in-depth for edge cases and the forkable/snap_repo subsystem which still uses the old patternTest plan
go test -race -count=3 -run TestHistoryVerification_SimpleBlocks ./execution/verify/...passes with no DATA RACE warningsgo build ./...passes🤖 Generated with Claude Code