Skip to content

Conversation

@onelapahead
Copy link
Contributor

For ExtraSmall runtimes with conservative rate limits - we need to retry much more slowly.

For general HTTP requests we use the Retry-After header if present, or just 1s, with random jitter up to 5s, to retry 429s.

For resources that use Retry to check the status of a resource before marking it completed (contract builds/actions, FireFly registrations, etc.) - we slow down the retry factor significantly, and add code to try to treat explicit 429 errors as retries.

@onelapahead onelapahead changed the title [resty] Retry-After w/ Jitter Support and Slower Status Checks [resty] [retry] Retry-After w/ Jitter Support and Slower Status Checks Jul 15, 2025
Comment on lines +126 to +135
SetRetryCount(5).
SetRetryAfter(func(c *resty.Client, r *resty.Response) (time.Duration, error) {
tflog.Debug(logCtx, fmt.Sprintf("retryAfter: %s", r.Header().Get("Retry-After")))
retryAfter, err := strconv.ParseFloat(r.Header().Get("Retry-After"), 64) // decimal seconds
if err != nil {
retryAfter = 1.0
}
jitter := time.Duration(rand.NormFloat64() * float64(5*time.Second)) // up to 5 second random jitter to account for 5 concurrent connections all retrying up to 5 times
return time.Duration(retryAfter*float64(time.Second)) + jitter, nil
}).
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should also consider adding throttling, so no matter what the client doesn't go faster than 1 req every 250ms ?

if err != nil {
retryAfter = 1.0
}
jitter := time.Duration(rand.NormFloat64() * float64(5*time.Second)) // up to 5 second random jitter to account for 5 concurrent connections all retrying up to 5 times
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is wrong - should rand.Float64() otherwise we could have negative jitter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants