Skip to content

Commit

Permalink
fix race condition when pinging peers (#13701)
Browse files Browse the repository at this point in the history
  • Loading branch information
qu0b authored Mar 7, 2024
1 parent 20d013a commit 4608569
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions beacon-chain/p2p/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type Service struct {
started bool
isPreGenesis bool
pingMethod func(ctx context.Context, id peer.ID) error
pingMethodLock sync.RWMutex
cancel context.CancelFunc
cfg *Config
peers *peers.Status
Expand Down Expand Up @@ -354,10 +355,14 @@ func (s *Service) MetadataSeq() uint64 {
// AddPingMethod adds the metadata ping rpc method to the p2p service, so that it can
// be used to refresh ENR.
func (s *Service) AddPingMethod(reqFunc func(ctx context.Context, id peer.ID) error) {
s.pingMethodLock.Lock()
s.pingMethod = reqFunc
s.pingMethodLock.Unlock()
}

func (s *Service) pingPeers() {
s.pingMethodLock.RLock()
defer s.pingMethodLock.RUnlock()
if s.pingMethod == nil {
return
}
Expand Down

0 comments on commit 4608569

Please sign in to comment.