From ff84dce1036389f1ccd6063236ca29525fb31c2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs?= Date: Fri, 10 Sep 2021 21:45:30 +0200 Subject: [PATCH] Avoid potential race condition --- plot/plot.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/plot/plot.go b/plot/plot.go index 3fa4f94..2721b22 100644 --- a/plot/plot.go +++ b/plot/plot.go @@ -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)