feat(client): add option to cap the Retry-After a 429 is retried for
What
Adds WithRetryAfterMax(d time.Duration), the Retry-After cap suggested in !3147 (merged) (note).
A 429 with a Retry-After longer than d, and no Ratelimit-Reset, is returned at once instead of retried.
Why
With WithRetryAfterBackoff(), a caller without a request deadline waits the full Retry-After for each retry. GitLab's application rate limits send the period of the limit, up to a day, so a CLI could block for hours.
glab wants to wait out the one-minute limits and fail fast on longer ones:
gitlab.WithRetryAfterBackoff(),
gitlab.WithRetryAfterMax(60 * time.Second),Behavior
- Off by default. Nothing changes without the option.
- Works with or without
WithRetryAfterBackoff(). Without it, the long 429 is no longer retried five times inside the same window. Ratelimit-Resetpresent: unchanged.- Unparseable
Retry-After: unchanged (retried). d = 0: every 429 with aRetry-Afteris returned at once.- Requests with
WithRequestRetryare not affected. - Over the cap, the client stops retrying and returns the 429.
Tests
retryHTTPCheck cases for: over the cap, at the cap, HTTP date, Ratelimit-Reset present, unparseable value, zero cap, no cap. One end-to-end test checks the 429 comes back from the first request without a wait. make reviewable passes.
Related to https://gitlab.com/gitlab-org/cli/-/work_items/8665