ethstats: use timer instead of time.After in loops #29241 (#1454)

This commit is contained in:
Daniel Liu 2025-09-13 10:06:25 +08:00 committed by GitHub
parent 48f93a8cc5
commit e34aea99f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -574,10 +574,13 @@ func (s *Service) reportLatency(conn *connWrapper) error {
return err
}
// Wait for the pong request to arrive back
timer := time.NewTimer(5 * time.Second)
defer timer.Stop()
select {
case <-s.pongCh:
// Pong delivered, report the latency
case <-time.After(5 * time.Second):
case <-timer.C:
// Ping timeout, abort
return errors.New("ping timed out")
}