eth/downloader: Fix race condition in Downloader.Cancel

- Happens when Cancel is called before WaitGroup.Add is called in spawnSync
This commit is contained in:
Pedro Pombeiro 2018-04-27 10:50:33 +02:00
parent 400332b99d
commit 41938be15f
No known key found for this signature in database
GPG key ID: A65DEB11E4BBC647

View file

@ -471,12 +471,18 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td *big.I
} else if d.mode == FullSync {
fetchers = append(fetchers, d.processFullSyncContent)
}
return d.spawnSync(fetchers)
return d.spawnSync(errCancelHeaderFetch, fetchers)
}
// spawnSync runs d.process and all given fetcher functions to completion in
// separate goroutines, returning the first error that appears.
func (d *Downloader) spawnSync(fetchers []func() error) error {
func (d *Downloader) spawnSync(errCancel error, fetchers []func() error) error {
select {
case <-d.cancelCh:
return errCancel
default:
}
errc := make(chan error, len(fetchers))
d.cancelWg.Add(len(fetchers))
for _, fn := range fetchers {