Skip to content

Commit 412f468

Browse files
thebsdboxScottGarman
authored andcommitted
Adds retry instead of immediate failure
Signed-off-by: Dan Finneran <dan@thebsdbox.co.uk>
1 parent 4d94180 commit 412f468

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

tink-docker/main.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,27 @@ func parseCmdLine(cmdLines []string) (cfg tinkConfig) {
7979
// downloadFile will download a url to a local file. It's efficient because it will
8080
// write as it downloads and not load the whole file into memory.
8181
func downloadFile(filepath string, url string) error {
82-
// Get the data
83-
resp, err := http.Get(url)
84-
if err != nil {
85-
return err
82+
// As all functions in the LinuxKit services run in parallel, ensure that we can fail
83+
// successfully until we accept that networking is actually broken
84+
85+
var maxRetryCount int
86+
var timeOut time.Duration
87+
maxRetryCount = 10
88+
timeOut = time.Millisecond * 500 // 0.5 seconds
89+
var resp *http.Response
90+
var err error
91+
92+
// Retry this task
93+
for retries := 0; retries < maxRetryCount; retries++ {
94+
// Get the data
95+
resp, err = http.Get(url)
96+
if err == nil {
97+
break
98+
}
99+
if retries == maxRetryCount-1 {
100+
return err
101+
}
102+
time.Sleep(timeOut)
86103
}
87104
defer resp.Body.Close()
88105

0 commit comments

Comments
 (0)