-
Notifications
You must be signed in to change notification settings - Fork 11
[resty] [retry] Retry-After w/ Jitter Support and Slower Status Checks #111
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
base: v1.1
Are you sure you want to change the base?
Conversation
Signed-off-by: hfuss <[email protected]>
Signed-off-by: hfuss <[email protected]>
Signed-off-by: hfuss <[email protected]>
Signed-off-by: hfuss <[email protected]>
| 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 | ||
| }). |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
For ExtraSmall runtimes with conservative rate limits - we need to retry much more slowly.
For general HTTP requests we use the
Retry-Afterheader if present, or just 1s, with random jitter up to 5s, to retry 429s.For resources that use
Retryto 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.