From ccd5fced8333f227addea641ab17fa3c82598764 Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Mon, 22 Jun 2026 17:55:50 +0200 Subject: [PATCH] eth/txtracker: make Stop safe before Start and idempotent --- eth/txtracker/tracker.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/eth/txtracker/tracker.go b/eth/txtracker/tracker.go index 93797cad9d..02da6f5a88 100644 --- a/eth/txtracker/tracker.go +++ b/eth/txtracker/tracker.go @@ -80,9 +80,10 @@ type Tracker struct { headCh chan core.ChainHeadEvent sub event.Subscription - quit chan struct{} - step chan struct{} // test sync: sent after each event is processed - wg sync.WaitGroup + quit chan struct{} + stopOnce sync.Once + step chan struct{} // test sync: sent after each event is processed + wg sync.WaitGroup } // New creates a new tracker. @@ -118,8 +119,12 @@ func (t *Tracker) NotifyPeerDrop(peer string) { // Stop shuts down the tracker. func (t *Tracker) Stop() { - t.sub.Unsubscribe() - close(t.quit) + t.stopOnce.Do(func() { + if t.sub != nil { + t.sub.Unsubscribe() + } + close(t.quit) + }) t.wg.Wait() }