Skip to content

Remove unguarded and unread peers field - #88

Open
damilolaedwards wants to merge 1 commit into
ethpandaops:masterfrom
damilolaedwards:fix/remove-dead-peers-field
Open

Remove unguarded and unread peers field#88
damilolaedwards wants to merge 1 commit into
ethpandaops:masterfrom
damilolaedwards:fix/remove-dead-peers-field

Conversation

@damilolaedwards

Copy link
Copy Markdown

Summary

n.peers was written from FetchPeers without any lock, racing between the 60s peers cron and any consumer calling FetchPeers directly. Nothing in the codebase ever read it: FetchPeers already returns the result directly, and metrics read peer counts off the published event instead.

Rather than just adding a lock to guard state nothing uses, this removes the field entirely, which removes the race along with the dead state.

Test plan

  • Added TestFetchPeersConcurrent in pkg/beacon/fetch_test.go, calling FetchPeers concurrently from 8 goroutines
  • Confirmed the test fails under -race against the old code and passes clean against the fix
  • go build ./..., go vet ./..., go test -race ./... all green

n.peers was written from FetchPeers without any lock, racing between
the peers cron and any consumer calling FetchPeers directly. Nothing
in the codebase ever read it, since FetchPeers already returns the
result directly and metrics read peer counts off the published
event. Removing the field removes the race entirely instead of just
guarding dead state.
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