Skip to content

Commit

Permalink
Added a context exit for request.
Browse files Browse the repository at this point in the history
Added a context cancel
  • Loading branch information
4gust committed Nov 7, 2024
1 parent 54ff161 commit 4e2ed03
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions apps/managedidentity/managedidentity.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,16 @@ func retry(maxRetries int, c ops.HTTPClient, req *http.Request) (*http.Response,
if attempt == maxRetries-1 {
return resp, err
}
io.Copy(io.Discard, resp.Body)
resp.Body.Close()

delay := time.Duration(time.Second)
time.Sleep(delay)
if resp != nil && resp.Body != nil {
io.Copy(io.Discard, resp.Body)
resp.Body.Close()
}
select {
case <-time.After(time.Second):
case <-req.Context().Done():
err = req.Context().Err()
return resp, err
}
}
return resp, err
}
Expand Down

0 comments on commit 4e2ed03

Please sign in to comment.