Skip to content

Commit

Permalink
Merge pull request #10 from chiafactory/race-conditions
Browse files Browse the repository at this point in the history
Avoid potential race condition
  • Loading branch information
trepca authored Sep 11, 2021
2 parents 6688b5b + ff84dce commit 4997300
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions plot/plot.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,14 +491,12 @@ func (p *Plot) RetryDownload(ctx context.Context) (err error) {

func (p *Plot) Download(ctx context.Context) (err error) {
ctx, cancel := context.WithCancel(ctx)
defer func() {
cancel()
p.cancelDownload = nil
}()

p.cancelDownload = cancel

defer func() {
p.cancelDownload()
p.cancelDownload = nil

if err != nil {
log.Errorf("%s download failed: %s", p, err.Error())
p.updateDownloadState(DownloadStateFailed)
Expand Down

0 comments on commit 4997300

Please sign in to comment.