Skip to content

Commit 3947b83

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

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

tink-docker/main.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,28 @@ 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+
// 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++ {
8294
// Get the data
83-
resp, err := http.Get(url)
84-
if err != nil {
95+
resp, err = http.Get(url)
96+
if err == nil {
97+
break
98+
}
99+
if retries == maxRetryCount - 1 {
85100
return err
86101
}
102+
time.Sleep(timeOut)
103+
}
87104
defer resp.Body.Close()
88105

89106
// Create the file

0 commit comments

Comments
 (0)