mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-01-12 03:21:33 +00:00
Cap delay to sleep to avoid overflow
This commit is contained in:
@@ -179,9 +179,9 @@ func (downloader *downloaderImpl) DownloadWithChecksum(ctx context.Context, url
|
||||
|
||||
var temppath string
|
||||
maxTries := downloader.maxTries
|
||||
const delayBase = 1
|
||||
const delayMax = time.Duration(5 * time.Minute)
|
||||
delay := time.Duration(1 * time.Second)
|
||||
const delayMultiplier = 2
|
||||
delay := time.Duration(delayBase * time.Second)
|
||||
for maxTries > 0 {
|
||||
temppath, err = downloader.download(req, url, destination, expected, ignoreMismatch)
|
||||
|
||||
@@ -192,8 +192,11 @@ func (downloader *downloaderImpl) DownloadWithChecksum(ctx context.Context, url
|
||||
}
|
||||
maxTries--
|
||||
time.Sleep(delay)
|
||||
// Sleep exponentially at the next retry
|
||||
// Sleep exponentially at the next retry, but no longer than delayMax
|
||||
delay *= delayMultiplier
|
||||
if delay > delayMax {
|
||||
delay = delayMax
|
||||
}
|
||||
} else {
|
||||
if downloader.progress != nil {
|
||||
downloader.progress.Printf("Error downloading %s: %s cannot retry...\n", url, err)
|
||||
|
||||
Reference in New Issue
Block a user