Skip to content

Commit 7cf83ce

Browse files
Domino Valdanokaralabe
authored andcommitted
eth/downloader: fix for Issue #16539 (#16546)
1 parent 744428c commit 7cf83ce

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

eth/downloader/downloader.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ func (d *Downloader) UnregisterPeer(id string) error {
306306
d.cancelLock.RUnlock()
307307

308308
if master {
309-
d.Cancel()
309+
d.cancel()
310310
}
311311
return nil
312312
}
@@ -501,8 +501,10 @@ func (d *Downloader) spawnSync(fetchers []func() error) error {
501501
return err
502502
}
503503

504-
// Cancel cancels all of the operations and resets the queue.
505-
func (d *Downloader) Cancel() {
504+
// cancel aborts all of the operations and resets the queue. However, cancel does
505+
// not wait for the running download goroutines to finish. This method should be
506+
// used when cancelling the downloads from inside the downloader.
507+
func (d *Downloader) cancel() {
506508
// Close the current cancel channel
507509
d.cancelLock.Lock()
508510
if d.cancelCh != nil {
@@ -514,6 +516,12 @@ func (d *Downloader) Cancel() {
514516
}
515517
}
516518
d.cancelLock.Unlock()
519+
}
520+
521+
// Cancel aborts all of the operations and waits for all download goroutines to
522+
// finish before returning.
523+
func (d *Downloader) Cancel() {
524+
d.cancel()
517525
d.cancelWg.Wait()
518526
}
519527

0 commit comments

Comments
 (0)