Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds retry instead of immediate failure #94

Merged
merged 1 commit into from
Nov 17, 2021
Merged
Changes from all 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
25 changes: 21 additions & 4 deletions tink-docker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,27 @@ func parseCmdLine(cmdLines []string) (cfg tinkConfig) {
// downloadFile will download a url to a local file. It's efficient because it will
// write as it downloads and not load the whole file into memory.
func downloadFile(filepath string, url string) error {
// Get the data
resp, err := http.Get(url)
if err != nil {
return err
// As all functions in the LinuxKit services run in parallel, ensure that we can fail
// successfully until we accept that networking is actually broken

var maxRetryCount int
var timeOut time.Duration
maxRetryCount = 10
timeOut = time.Millisecond * 500 // 0.5 seconds
var resp *http.Response
var err error

// Retry this task
for retries := 0; retries < maxRetryCount; retries++ {
// Get the data
resp, err = http.Get(url)
ScottGarman marked this conversation as resolved.
Show resolved Hide resolved
if err == nil {
break
}
if retries == maxRetryCount-1 {
return err
}
time.Sleep(timeOut)
}
defer resp.Body.Close()

Expand Down