Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion binrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (m *Manager) installBinary(version *GoVersion) (string, error) {
}

goURL := fmt.Sprintf("%s/go%v.%v-%v.%v", m.GoStorageHome, version, m.GOOS, m.GOARCH, extension)
path, err := common.DownloadFile(goURL, tmp, m.HTTPTimeout)
path, err := common.DownloadFile(goURL, tmp, m.HTTPTimeout, common.DefaultRetryParams)
if err != nil {
return "", fmt.Errorf("failed downloading from %v: %w", goURL, err)
}
Expand Down
18 changes: 15 additions & 3 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,27 @@ var log = logrus.WithField("package", "common")
// ErrNotFound is returned when the download fails due to HTTP 404 Not Found.
var ErrNotFound = errors.New("not found")

func DownloadFile(url, destinationDir string, httpTimeout time.Duration) (string, error) {
type retryParams struct {
maxRetries int
retryDelay time.Duration
}

var DefaultRetryParams = retryParams{
maxRetries: 5,
retryDelay: 10 * time.Second,
}

func DownloadFile(url, destinationDir string, httpTimeout time.Duration, r retryParams) (string, error) {
log.WithField("url", url).Debug("Downloading file")
var name string
var err error
var retry bool
for a := 1; a <= 3; a++ {

for a := 1; a <= r.maxRetries; a++ {
name, retry, err = downloadFile(url, destinationDir, httpTimeout)
if err != nil && retry {
log.WithError(err).Debugf("Download attempt %d failed", a)
log.WithError(err).Debugf("Download attempt %d/%d failed, retrying in %s", a, r.maxRetries, r.retryDelay)
time.Sleep(r.retryDelay)
continue
}
break
Expand Down