Skip to content

eth/protocols/snap: fix data race on testPeer counters#34802

Open
rayjun wants to merge 1 commit intoethereum:masterfrom
rayjun:fix/snap-test-counter-data-race
Open

eth/protocols/snap: fix data race on testPeer counters#34802
rayjun wants to merge 1 commit intoethereum:masterfrom
rayjun:fix/snap-test-counter-data-race

Conversation

@rayjun
Copy link
Copy Markdown
Contributor

@rayjun rayjun commented Apr 23, 2026

The testPeer request counters (nAccountRequests, nStorageRequests, nBytecodeRequests, nTrienodeRequests) were plain int fields incremented with ++. These increments happen in Request* methods that are invoked concurrently by the Syncer from multiple goroutines (assignBytecodeTasks, assignStorageTasks, etc.), causing a data race reliably detected by go test -race.

Change the counters to atomic.Int64 so increments and reads are synchronized without introducing a mutex.

Fixes races detected in TestMultiSyncManyUseless,
TestMultiSyncManyUselessWithLowTimeout,
TestMultiSyncManyUnresponsive, TestSyncWithStorageAndOneCappedPeer, TestSyncWithStorageAndCorruptPeer, and
TestSyncWithStorageAndNonProvingPeer.

The testPeer request counters (nAccountRequests, nStorageRequests,
nBytecodeRequests, nTrienodeRequests) were plain int fields
incremented with ++. These increments happen in Request* methods
that are invoked concurrently by the Syncer from multiple goroutines
(assignBytecodeTasks, assignStorageTasks, etc.), causing a data
race reliably detected by go test -race.

Change the counters to atomic.Int64 so increments and reads are
synchronized without introducing a mutex.

Fixes races detected in TestMultiSyncManyUseless,
TestMultiSyncManyUselessWithLowTimeout,
TestMultiSyncManyUnresponsive, TestSyncWithStorageAndOneCappedPeer,
TestSyncWithStorageAndCorruptPeer, and
TestSyncWithStorageAndNonProvingPeer.
@rayjun rayjun requested a review from rjl493456442 as a code owner April 23, 2026 07:33
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.

1 participant