eth/txtracker: make Stop safe before Start and idempotent

This commit is contained in:
Csaba Kiraly 2026-06-22 17:55:50 +02:00
parent 00c5d3214a
commit ccd5fced83

View file

@ -80,9 +80,10 @@ type Tracker struct {
headCh chan core.ChainHeadEvent headCh chan core.ChainHeadEvent
sub event.Subscription sub event.Subscription
quit chan struct{} quit chan struct{}
step chan struct{} // test sync: sent after each event is processed stopOnce sync.Once
wg sync.WaitGroup step chan struct{} // test sync: sent after each event is processed
wg sync.WaitGroup
} }
// New creates a new tracker. // New creates a new tracker.
@ -118,8 +119,12 @@ func (t *Tracker) NotifyPeerDrop(peer string) {
// Stop shuts down the tracker. // Stop shuts down the tracker.
func (t *Tracker) Stop() { func (t *Tracker) Stop() {
t.sub.Unsubscribe() t.stopOnce.Do(func() {
close(t.quit) if t.sub != nil {
t.sub.Unsubscribe()
}
close(t.quit)
})
t.wg.Wait() t.wg.Wait()
} }