aboutsummaryrefslogtreecommitdiffstats
path: root/eth/downloader
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-05-30 17:01:50 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-05-30 17:01:50 +0800
commit4496a44f68246bf128bb822c3f3a98f38adfdbdd (patch)
tree312922dbfc111fd3ef66c194dcdc6c87b96bba66 /eth/downloader
parentab664c7e17009729d1083d8d4f7c37eb387012d3 (diff)
downloadgo-tangerine-4496a44f68246bf128bb822c3f3a98f38adfdbdd.tar
go-tangerine-4496a44f68246bf128bb822c3f3a98f38adfdbdd.tar.gz
go-tangerine-4496a44f68246bf128bb822c3f3a98f38adfdbdd.tar.bz2
go-tangerine-4496a44f68246bf128bb822c3f3a98f38adfdbdd.tar.lz
go-tangerine-4496a44f68246bf128bb822c3f3a98f38adfdbdd.tar.xz
go-tangerine-4496a44f68246bf128bb822c3f3a98f38adfdbdd.tar.zst
go-tangerine-4496a44f68246bf128bb822c3f3a98f38adfdbdd.zip
eth/downloader: ensure cancel channel is closed post sync
Diffstat (limited to 'eth/downloader')
-rw-r--r--eth/downloader/downloader.go2
-rw-r--r--eth/downloader/downloader_test.go12
2 files changed, 13 insertions, 1 deletions
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go
index 74bff2b66..f1a589fa6 100644
--- a/eth/downloader/downloader.go
+++ b/eth/downloader/downloader.go
@@ -332,6 +332,8 @@ func (d *Downloader) synchronise(id string, hash common.Hash, td *big.Int, mode
d.cancelCh = make(chan struct{})
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
d.mode = mode
if d.mode == FastSync && d.noFast {
diff --git a/eth/downloader/downloader_test.go b/eth/downloader/downloader_test.go
index 4ea8a8abe..1cf0e7cd3 100644
--- a/eth/downloader/downloader_test.go
+++ b/eth/downloader/downloader_test.go
@@ -188,7 +188,17 @@ func (dl *downloadTester) sync(id string, td *big.Int, mode SyncMode) error {
}
}
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.