From e34aea99f083cc6aac10b9936520940eb73edd1b Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Sat, 13 Sep 2025 10:06:25 +0800 Subject: [PATCH] ethstats: use timer instead of time.After in loops #29241 (#1454) --- ethstats/ethstats.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ethstats/ethstats.go b/ethstats/ethstats.go index 0bdba96e7a..3b20d561c0 100644 --- a/ethstats/ethstats.go +++ b/ethstats/ethstats.go @@ -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") }