Skip to content

Commit cd13417

Browse files
committed
[release/1.4.6] eth/downloader: ensure cancel channel is closed post sync
(cherry picked from commit 4496a44)
1 parent 4918c82 commit cd13417

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

eth/downloader/downloader.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ func (d *Downloader) synchronise(id string, hash common.Hash, td *big.Int, mode
326326
d.cancelCh = make(chan struct{})
327327
d.cancelLock.Unlock()
328328

329+
defer d.cancel() // No matter what, we can't leave the cancel channel open
330+
329331
// Set the requested sync mode, unless it's forbidden
330332
d.mode = mode
331333
if d.mode == FastSync && d.noFast {

eth/downloader/downloader_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,17 @@ func (dl *downloadTester) sync(id string, td *big.Int, mode SyncMode) error {
188188
}
189189
}
190190
dl.lock.RUnlock()
191-
return dl.downloader.synchronise(id, hash, td, mode)
191+
192+
// Synchronise with the chosen peer and ensure proper cleanup afterwards
193+
err := dl.downloader.synchronise(id, hash, td, mode)
194+
select {
195+
case <-dl.downloader.cancelCh:
196+
// Ok, downloader fully cancelled after sync cycle
197+
default:
198+
// Downloader is still accepting packets, can block a peer up
199+
panic("downloader active post sync cycle") // panic will be caught by tester
200+
}
201+
return err
192202
}
193203

194204
// hasHeader checks if a header is present in the testers canonical chain.

0 commit comments

Comments
 (0)