mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
eth/downloader: remove cancelTimeout channel
This commit is contained in:
parent
1b19b21cb2
commit
c7e5270c70
1 changed files with 6 additions and 8 deletions
|
|
@ -77,19 +77,15 @@ func (d *Downloader) stateFetcher() {
|
||||||
// runStateSync runs s until it completes or another stateSync is requested.
|
// runStateSync runs s until it completes or another stateSync is requested.
|
||||||
func (d *Downloader) runStateSync(s *stateSync) *stateSync {
|
func (d *Downloader) runStateSync(s *stateSync) *stateSync {
|
||||||
var (
|
var (
|
||||||
activeReqs = make(map[string]*stateReq)
|
activeReqs = make(map[string]*stateReq)
|
||||||
finishedReqs []*stateReq
|
finishedReqs []*stateReq
|
||||||
timeout = make(chan *stateReq)
|
timeout = make(chan *stateReq)
|
||||||
cancelTimeout = make(chan struct{})
|
|
||||||
)
|
)
|
||||||
// Cancel active request timers on exit.
|
// Cancel active request timers on exit.
|
||||||
// The cancelTimeout channel prevents leaking of timer goroutines
|
|
||||||
// in the unlikely case where a timer is fired just before canceling it.
|
|
||||||
defer func() {
|
defer func() {
|
||||||
for _, req := range activeReqs {
|
for _, req := range activeReqs {
|
||||||
req.timer.Stop()
|
req.timer.Stop()
|
||||||
}
|
}
|
||||||
close(cancelTimeout)
|
|
||||||
}()
|
}()
|
||||||
// Run the state sync.
|
// Run the state sync.
|
||||||
go s.run()
|
go s.run()
|
||||||
|
|
@ -141,7 +137,9 @@ func (d *Downloader) runStateSync(s *stateSync) *stateSync {
|
||||||
req.timer = time.AfterFunc(req.timeout, func() {
|
req.timer = time.AfterFunc(req.timeout, func() {
|
||||||
select {
|
select {
|
||||||
case timeout <- req:
|
case timeout <- req:
|
||||||
case <-cancelTimeout:
|
case <-s.done:
|
||||||
|
// Prevent leaking of timer goroutines in the unlikely case where a
|
||||||
|
// timer is fired just before exiting runStateSync.
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue