-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Use a max retry after duration for secondary rate limit if specified #3438
Use a max retry after duration for secondary rate limit if specified #3438
Conversation
@@ -174,6 +174,10 @@ type Client struct { | |||
rateLimits [Categories]Rate // Rate limits for the client as determined by the most recent API calls. | |||
secondaryRateLimitReset time.Time // Secondary rate limit reset for the client as determined by the most recent API calls. | |||
|
|||
// If specified, Client will block requests for at most this duration in case of reaching a secondary | |||
// rate limit | |||
MaxSecondaryRateLimitRetryAfterDuration time.Duration |
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.
I'm letting users specify their desired max duration. We could enforce a minimum or a default value here if we want to make sure users are not using this field incorrectly
// if a max duration is specified, make sure that we are waiting at most this duration | ||
if c.MaxSecondaryRateLimitRetryAfterDuration > 0 && rerr.GetRetryAfter() > c.MaxSecondaryRateLimitRetryAfterDuration { | ||
rerr.RetryAfter = &c.MaxSecondaryRateLimitRetryAfterDuration | ||
} |
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.
I wanted to enforce the max duration in the parseSecondaryRate
function but we don't have access to the client there, and it was tedious to pass a parameter downstream so I'm mutating the error here instead. Let me know if you would prefer another solution
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3438 +/- ##
==========================================
- Coverage 97.72% 92.26% -5.46%
==========================================
Files 153 174 +21
Lines 13390 15026 +1636
==========================================
+ Hits 13085 13864 +779
- Misses 215 1068 +853
- Partials 90 94 +4 ☔ View full report in Codecov by Sentry. |
3e7ca0d
to
b810986
Compare
I am extremely leery of changing the default behavior regarding rate limiting. @wmouchere - please comment on this PR because of your recent work on #3411. |
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.
Thank you, @Letiste.
LGTM.
Awaiting second LGTM+Approval from any other contributor to this repo before merging.
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.
LGTM
Thank you, @stevehipwell! |
The current logic to pick a retry after duration in case of a secondary rate limit is to first check for the retry after header, and if not found, use the primary rate limit reset time. As the primary rate limit reset every hour, we can be blocked for as long as 1 hour when GitHub returns a secondary rate limit error without a retry after header.
According to GitHub documentation, the rate limit reset header should be used when the remaining allowed requests reached 0. Otherwise, retry in 1 min (doc):
This PR adds an optional max wait time for the secondary rate limit that will, if specified, prevents the client to block up to 1h in some cases.
Given that the GitHub documentation specifies to use the rate limit reset header only if there is no more requests remaining in the quota, I was tempted to make this change by default but it would change the current behaviour. Should we make it by default regardless?