eth/downloader: ensure cancel channel is closed post sync
This commit is contained in:
parent
ab664c7e17
commit
4496a44f68
|
@ -332,6 +332,8 @@ func (d *Downloader) synchronise(id string, hash common.Hash, td *big.Int, mode
|
||||||
d.cancelCh = make(chan struct{})
|
d.cancelCh = make(chan struct{})
|
||||||
d.cancelLock.Unlock()
|
d.cancelLock.Unlock()
|
||||||
|
|
||||||
|
defer d.cancel() // No matter what, we can't leave the cancel channel open
|
||||||
|
|
||||||
// Set the requested sync mode, unless it's forbidden
|
// Set the requested sync mode, unless it's forbidden
|
||||||
d.mode = mode
|
d.mode = mode
|
||||||
if d.mode == FastSync && d.noFast {
|
if d.mode == FastSync && d.noFast {
|
||||||
|
|
|
@ -188,7 +188,17 @@ func (dl *downloadTester) sync(id string, td *big.Int, mode SyncMode) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dl.lock.RUnlock()
|
dl.lock.RUnlock()
|
||||||
return dl.downloader.synchronise(id, hash, td, mode)
|
|
||||||
|
// Synchronise with the chosen peer and ensure proper cleanup afterwards
|
||||||
|
err := dl.downloader.synchronise(id, hash, td, mode)
|
||||||
|
select {
|
||||||
|
case <-dl.downloader.cancelCh:
|
||||||
|
// Ok, downloader fully cancelled after sync cycle
|
||||||
|
default:
|
||||||
|
// Downloader is still accepting packets, can block a peer up
|
||||||
|
panic("downloader active post sync cycle") // panic will be caught by tester
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// hasHeader checks if a header is present in the testers canonical chain.
|
// hasHeader checks if a header is present in the testers canonical chain.
|
||||||
|
|
Loading…
Reference in New Issue