ethstats: stop report ticker in each loop cycle #21071 (#1440)

Co-authored-by: Hao Duan <duanhao0814@gmail.com>
This commit is contained in:
Daniel Liu 2025-09-06 17:17:40 +08:00 committed by GitHub
parent 3032fb1fca
commit 65c7f4418f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -206,7 +206,7 @@ func (s *Service) loop() {
defer forensicsSub.Unsubscribe() 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 ( var (
quitCh = make(chan struct{}) quitCh = make(chan struct{})
headCh = make(chan *types.Block, 1) headCh = make(chan *types.Block, 1)
@ -252,15 +252,17 @@ func (s *Service) loop() {
} }
close(quitCh) 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 // Loop reporting until termination
for { 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 // Establish a websocket connection to the server on any supported URL
var ( var (
conn *connWrapper conn *connWrapper
@ -304,6 +306,8 @@ func (s *Service) loop() {
for err == nil { for err == nil {
select { select {
case <-quitCh: case <-quitCh:
fullReport.Stop()
// Make sure the connection is closed
conn.Close() conn.Close()
return return
@ -332,6 +336,7 @@ func (s *Service) loop() {
} }
} }
} }
fullReport.Stop()
// Make sure the connection is closed // Make sure the connection is closed
conn.Close() conn.Close()
} }