From 65c7f4418f00200b7f6e31c3447496dd35c6ca57 Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Sat, 6 Sep 2025 17:17:40 +0800 Subject: [PATCH] ethstats: stop report ticker in each loop cycle #21071 (#1440) Co-authored-by: Hao Duan --- ethstats/ethstats.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/ethstats/ethstats.go b/ethstats/ethstats.go index 7c1253a9ae..9f9bff357b 100644 --- a/ethstats/ethstats.go +++ b/ethstats/ethstats.go @@ -206,7 +206,7 @@ func (s *Service) loop() { defer forensicsSub.Unsubscribe() } - // Start a goroutine that exhausts the subsciptions to avoid events piling up + // Start a goroutine that exhausts the subscriptions to avoid events piling up var ( quitCh = make(chan struct{}) headCh = make(chan *types.Block, 1) @@ -252,15 +252,17 @@ func (s *Service) loop() { } close(quitCh) }() + + // Resolve the URL, defaulting to TLS, but falling back to none too + path := fmt.Sprintf("%s/api", s.host) + urls := []string{path} + + // url.Parse and url.IsAbs is unsuitable (https://github.com/golang/go/issues/19779) + if !strings.Contains(path, "://") { + urls = []string{"wss://" + path, "ws://" + path} + } // Loop reporting until termination for { - // Resolve the URL, defaulting to TLS, but falling back to none too - path := fmt.Sprintf("%s/api", s.host) - urls := []string{path} - - if !strings.Contains(path, "://") { // url.Parse and url.IsAbs is unsuitable (https://github.com/golang/go/issues/19779) - urls = []string{"wss://" + path, "ws://" + path} - } // Establish a websocket connection to the server on any supported URL var ( conn *connWrapper @@ -304,6 +306,8 @@ func (s *Service) loop() { for err == nil { select { case <-quitCh: + fullReport.Stop() + // Make sure the connection is closed conn.Close() return @@ -332,6 +336,7 @@ func (s *Service) loop() { } } } + fullReport.Stop() // Make sure the connection is closed conn.Close() }