mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
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:
parent
400332b99d
commit
41938be15f
1 changed files with 8 additions and 2 deletions
|
|
@ -471,12 +471,18 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td *big.I
|
||||||
} else if d.mode == FullSync {
|
} else if d.mode == FullSync {
|
||||||
fetchers = append(fetchers, d.processFullSyncContent)
|
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
|
// spawnSync runs d.process and all given fetcher functions to completion in
|
||||||
// separate goroutines, returning the first error that appears.
|
// 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))
|
errc := make(chan error, len(fetchers))
|
||||||
d.cancelWg.Add(len(fetchers))
|
d.cancelWg.Add(len(fetchers))
|
||||||
for _, fn := range fetchers {
|
for _, fn := range fetchers {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue