Skip to content

Conversation

@miagilepner
Copy link
Contributor

@miagilepner miagilepner commented Jun 3, 2025

This backoff combines checking retry headers with linear jitter. This is used by both Boundary and Vault, so it makes sense to have it in the shared library.

@miagilepner miagilepner requested review from a team as code owners June 3, 2025 16:12
@miagilepner miagilepner changed the title Add a new RetryHeaderLinearJitterBackoff policy Add a new RateLimitLinearJitterBackoff policy Jun 5, 2025
jackofallops
jackofallops previously approved these changes Jun 18, 2025
Copy link
Member

@jackofallops jackofallops left a comment

Choose a reason for hiding this comment

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

THanks @miagilepner - LGTM 👍

Copy link

@abhijeetviswa abhijeetviswa left a comment

Choose a reason for hiding this comment

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

The changes look fine. However, does it makes sense to

Comment on lines +648 to +654
if resp != nil {
if resp.StatusCode == http.StatusTooManyRequests || resp.StatusCode == http.StatusServiceUnavailable {
if sleep, ok := parseRetryAfterHeader(resp.Header["Retry-After"]); ok {
return sleep
}
}
}

Choose a reason for hiding this comment

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

Does it makes sene to ignore Retry-After if it isn't 503 or 429? From what I've understood, the spec doesn't specify the status codes for which this header is valid but instead identifies what the header means for specific status codes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe the only other case where a Retry-After header should be sent is with a redirect status. The HTTP client will do redirecting as part of c.HTTPClient.Do, before we get to any retrying, so it's unlikely that we'll end up here with a 3xx status code, but I suppose it's possible.

I can update this to parse the header regardless of status code

Choose a reason for hiding this comment

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

Tbh, I'm not really sure what is the correct way to handle the header. If there is a req to handle other status codes, we'll deal with it then. I'll approve the PR for now. Thanks!

Choose a reason for hiding this comment

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

I see you've already push a commit to ignore the status code. I'm okay with either way of handling the header.

Comment on lines +641 to +646
// RateLimitLinearJitterBackoff wraps the retryablehttp.LinearJitterBackoff.
// It first checks if the response status code is http.StatusTooManyRequests
// (HTTP Code 429) or http.StatusServiceUnavailable (HTTP Code 503). If it is
// and the response contains a Retry-After response header, it will wait the
// amount of time specified by the header. Otherwise, this calls
// LinearJitterBackoff.

Choose a reason for hiding this comment

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

After removing the status codes checks, the documentation is no longer correct. Let's either fix this or undo the commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted the commit

@miagilepner miagilepner force-pushed the miagilepner/VAULT-36112-retry-after-header branch from a958a6a to 7096c34 Compare June 18, 2025 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants