mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +00:00
eth/txtracker: make Stop safe before Start and idempotent
This commit is contained in:
parent
00c5d3214a
commit
ccd5fced83
1 changed files with 10 additions and 5 deletions
|
|
@ -81,6 +81,7 @@ type Tracker struct {
|
||||||
sub event.Subscription
|
sub event.Subscription
|
||||||
|
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
|
stopOnce sync.Once
|
||||||
step chan struct{} // test sync: sent after each event is processed
|
step chan struct{} // test sync: sent after each event is processed
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
}
|
}
|
||||||
|
|
@ -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.stopOnce.Do(func() {
|
||||||
|
if t.sub != nil {
|
||||||
t.sub.Unsubscribe()
|
t.sub.Unsubscribe()
|
||||||
|
}
|
||||||
close(t.quit)
|
close(t.quit)
|
||||||
|
})
|
||||||
t.wg.Wait()
|
t.wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue