Skip to content

Commit 4496a44

Browse files
committed
eth/downloader: ensure cancel channel is closed post sync
1 parent ab664c7 commit 4496a44

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎eth/downloader/downloader.go‎

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

335+
defer d.cancel() // No matter what, we can't leave the cancel channel open
336+
335337
// Set the requested sync mode, unless it's forbidden
336338
d.mode = mode
337339
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)