Skip to content

[SharovBot] Fix data race on bheapCache in db/rawdb#19606

Merged
AskAlexSharov merged 1 commit intomainfrom
fix/bheapcache-data-race
Mar 4, 2026
Merged

[SharovBot] Fix data race on bheapCache in db/rawdb#19606
AskAlexSharov merged 1 commit intomainfrom
fix/bheapcache-data-race

Conversation

@Giulio2002
Copy link
Collaborator

[SharovBot]

Summary

  • Fix DATA RACE between TestBlockStorage and TestBadBlocks in db/rawdb
  • Add sync.RWMutex to protect concurrent access to the package-level bheapCache variable
  • The variable was being read in TruncateCanonicalHash and written in ResetBadBlockCache without synchronization

Test plan

  • go test -race ./db/rawdb/... -run "TestBlockStorage|TestBadBlocks" -count=3 passes with no DATA RACE
  • go build ./... passes
  • No test files modified

🤖 Generated with Claude Code

Add sync.RWMutex to protect concurrent access to the package-level
bheapCache variable, which was being read in TruncateCanonicalHash
and written in ResetBadBlockCache without synchronization.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Collaborator

@AskAlexSharov AskAlexSharov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feels like need methods around bheapCache for this which will lock/unlock

@AskAlexSharov AskAlexSharov merged commit 9a00f9a into main Mar 4, 2026
24 checks passed
@AskAlexSharov AskAlexSharov deleted the fix/bheapcache-data-race branch March 4, 2026 13:33
sudeepdino008 pushed a commit that referenced this pull request Mar 4, 2026
**[SharovBot]**

## Summary
- Fix DATA RACE between `TestBlockStorage` and `TestBadBlocks` in
`db/rawdb`
- Add `sync.RWMutex` to protect concurrent access to the package-level
`bheapCache` variable
- The variable was being read in `TruncateCanonicalHash` and written in
`ResetBadBlockCache` without synchronization

## Test plan
- [x] `go test -race ./db/rawdb/... -run
"TestBlockStorage|TestBadBlocks" -count=3` passes with no DATA RACE
- [x] `go build ./...` passes
- [x] No test files modified

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants