Skip to content

eth/downloader: fix for Issue #16539 #16546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions eth/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func (d *Downloader) UnregisterPeer(id string) error {
d.cancelLock.RUnlock()

if master {
d.Cancel()
d.cancel()
}
return nil
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
}

Expand Down