From de2be9b8aec4822d127c9da8da34ad172e70891f Mon Sep 17 00:00:00 2001 From: Lorenzo Bolla Date: Wed, 23 Jun 2021 13:53:45 +0200 Subject: [PATCH] Sleep between retries to download from http Fix #1 --- http/download.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/http/download.go b/http/download.go index 6ac38343..57a4d189 100644 --- a/http/download.go +++ b/http/download.go @@ -179,6 +179,9 @@ func (downloader *downloaderImpl) DownloadWithChecksum(ctx context.Context, url var temppath string maxTries := downloader.maxTries + const delayBase = 1 + const delayMultiplier = 2 + delay := time.Duration(delayBase * time.Second) for maxTries > 0 { temppath, err = downloader.download(req, url, destination, expected, ignoreMismatch) @@ -188,6 +191,9 @@ func (downloader *downloaderImpl) DownloadWithChecksum(ctx context.Context, url downloader.progress.Printf("Error downloading %s: %s retrying...\n", url, err) } maxTries-- + time.Sleep(delay) + // Sleep exponentially at the next retry + delay *= delayMultiplier } else { if downloader.progress != nil { downloader.progress.Printf("Error downloading %s: %s cannot retry...\n", url, err)