eth/downloader: remove cancelTimeout channel

This commit is contained in:
Felix Lange 2017-05-30 10:38:09 +02:00 committed by Péter Szilágyi
parent 1b19b21cb2
commit c7e5270c70
No known key found for this signature in database
GPG key ID: E9AE538CEDF8293D

View file

@ -77,19 +77,15 @@ func (d *Downloader) stateFetcher() {
// runStateSync runs s until it completes or another stateSync is requested.
func (d *Downloader) runStateSync(s *stateSync) *stateSync {
var (
activeReqs = make(map[string]*stateReq)
finishedReqs []*stateReq
timeout = make(chan *stateReq)
cancelTimeout = make(chan struct{})
activeReqs = make(map[string]*stateReq)
finishedReqs []*stateReq
timeout = make(chan *stateReq)
)
// 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() {
for _, req := range activeReqs {
req.timer.Stop()
}
close(cancelTimeout)
}()
// Run the state sync.
go s.run()
@ -141,7 +137,9 @@ func (d *Downloader) runStateSync(s *stateSync) *stateSync {
req.timer = time.AfterFunc(req.timeout, func() {
select {
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.
}
})
}