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

Extend retryablehttp limits in SDK base client #945

Merged
merged 1 commit into from
Mar 27, 2024
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
16 changes: 14 additions & 2 deletions sdk/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ func (c *Client) Execute(ctx context.Context, req *Request) (*Response, error) {
}

// Instantiate a RetryableHttp client and configure its CheckRetry func
r := c.retryableClient(func(ctx context.Context, r *http.Response, err error) (bool, error) {
r := c.retryableClient(ctx, func(ctx context.Context, r *http.Response, err error) (bool, error) {
// First check for badly malformed responses
if r == nil {
if req.IsIdempotent() {
Expand Down Expand Up @@ -647,7 +647,7 @@ func (c *Client) ExecutePaged(ctx context.Context, req *Request) (*Response, err
}

// retryableClient instantiates a new *retryablehttp.Client having the provided checkRetry func
func (c *Client) retryableClient(checkRetry retryablehttp.CheckRetry) (r *retryablehttp.Client) {
func (c *Client) retryableClient(ctx context.Context, checkRetry retryablehttp.CheckRetry) (r *retryablehttp.Client) {
r = retryablehttp.NewClient()

r.Backoff = func(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
Expand All @@ -672,6 +672,18 @@ func (c *Client) retryableClient(checkRetry retryablehttp.CheckRetry) (r *retrya
r.CheckRetry = checkRetry
r.ErrorHandler = RetryableErrorHandler
r.Logger = log.Default()
r.RetryWaitMin = 1 * time.Second
r.RetryWaitMax = 61 * time.Second
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW some ARM API's do have Retry-After headers with an excessive timeout (e.g. 10m) - but I don't see any harm in us polling more regularly given that extended interval so 👍

Copy link
Contributor Author

@manicminer manicminer Mar 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh if the response includes a Retry-After header, that is always respected/selected first before falling back to exponential backoff (i.e. these are not used in that case)


// Default RetryMax of 16 takes approx 10 minutes to iterate
r.RetryMax = 16

// Extend the RetryMax if the context timeout exceeds 10 minutes
if deadline, ok := ctx.Deadline(); ok {
if timeout := deadline.Sub(time.Now()); timeout > 10*time.Minute {
r.RetryMax = int(math.Round(timeout.Minutes())) + 6
}
}

tlsConfig := tls.Config{
MinVersion: tls.VersionTLS12,
Expand Down
Loading