aboutsummaryrefslogtreecommitdiffstats
path: root/eth/downloader
diff options
context:
space:
mode:
authorDomino Valdano <jeff@okcupid.com>2018-04-23 15:01:21 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-04-23 15:01:21 +0800
commit7cf83cee5240f76bdf8ff4f1024643fd126e1018 (patch)
tree27bba9126bb8693ad18fc0547b15df3003bd9f84 /eth/downloader
parent744428cb03ea8de8f219708f57d2e197acb6689b (diff)
downloaddexon-7cf83cee5240f76bdf8ff4f1024643fd126e1018.tar.gz
dexon-7cf83cee5240f76bdf8ff4f1024643fd126e1018.tar.zst
dexon-7cf83cee5240f76bdf8ff4f1024643fd126e1018.zip
eth/downloader: fix for Issue #16539 (#16546)
Diffstat (limited to 'eth/downloader')
-rw-r--r--eth/downloader/downloader.go14
1 files changed, 11 insertions, 3 deletions
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go
index 8b181b8ad..43f0e3db9 100644
--- a/eth/downloader/downloader.go
+++ b/eth/downloader/downloader.go
@@ -306,7 +306,7 @@ func (d *Downloader) UnregisterPeer(id string) error {
d.cancelLock.RUnlock()
if master {
- d.Cancel()
+ d.cancel()
}
return nil
}
@@ -501,8 +501,10 @@ func (d *Downloader) spawnSync(fetchers []func() error) error {
return err
}
-// Cancel cancels all of the operations and resets the queue.
-func (d *Downloader) Cancel() {
+// cancel aborts all of the operations and resets the queue. However, cancel does
+// not wait for the running download goroutines to finish. This method should be
+// used when cancelling the downloads from inside the downloader.
+func (d *Downloader) cancel() {
// Close the current cancel channel
d.cancelLock.Lock()
if d.cancelCh != nil {
@@ -514,6 +516,12 @@ func (d *Downloader) Cancel() {
}
}
d.cancelLock.Unlock()
+}
+
+// Cancel aborts all of the operations and waits for all download goroutines to
+// finish before returning.
+func (d *Downloader) Cancel() {
+ d.cancel()
d.cancelWg.Wait()
}