Skip to content
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

Client.RateLimits shouldn't return RateLimitError #1899

Closed
sa-spag opened this issue Jun 17, 2021 · 5 comments · Fixed by #1907
Closed

Client.RateLimits shouldn't return RateLimitError #1899

sa-spag opened this issue Jun 17, 2021 · 5 comments · Fixed by #1907

Comments

@sa-spag
Copy link
Contributor

sa-spag commented Jun 17, 2021

👋 Hello,

I noticed that Client.RateLimits can return a RateLimitError, as per:

go-github/github/github.go

Lines 648 to 652 in 75644ea

return &RateLimitError{
Rate: rate,
Response: resp,
Message: fmt.Sprintf("API rate limit of %v still exceeded until %v, not making remote request.", rate.Limit, rate.Reset.Time),
}

According to GitHub REST API documentation, rate limit status can be checked "at any time using the Rate Limit API", i.e. even when the remaining number of allowed requests is 0, and the GET /rate_limit endpoint never responds with a HTTP 403. I verified myself and I can confirm the documentation is accurate. Therefore, I think Client.RateLimits should never return RateLimitError errors and return the actual rate limit status, by performing a HTTP request.

I have 2 solutions in mind:

  • Client.checkRateLimitBeforeDo is aware of some allowlist of endpoints, including GET /rate_limits (and perhaps others I don't know yet about), for which it should always return nil;
  • a higher layer passes a boolean which indicates that the request should not be subject to the pre-request rate limit check, possibly exposed to the user so one could hit GitHub API regardless of the internal rate limit status.

Happy to discuss any solution before I (or someone else) patch(es) the issue. Thanks!

@gmlewis
Copy link
Collaborator

gmlewis commented Jun 17, 2021

May I please ask what the actual problem is that you are trying to solve?

In other words, why is it a problem that Client.RateLimits() returns a RateLimitError (which, by the way, should have all the information you need to avoid causing the next rate limit error... specifically the Reset timestamp)?

@sa-spag
Copy link
Contributor Author

sa-spag commented Jun 18, 2021

May I please ask what the actual problem is that you are trying to solve?

RateLimitError only exposes the rate limit status for the request's category, i.e. core for GET /rate_limits, but there are a bunch of other "resources" for which rate limit is independent and for which I would like to request an up-to-date status.

@gmlewis
Copy link
Collaborator

gmlewis commented Jun 18, 2021

I suppose a third option is to modify Client.RateLimits() to always perform the call regardless of saved history by bypassing the existing check.

@sa-spag
Copy link
Contributor Author

sa-spag commented Jun 22, 2021

I suppose a third option is to modify Client.RateLimits() to always perform the call regardless of saved history by bypassing the existing check.

Thanks for your feedback. Exactly, and I think we have at least 2 ways of implementing such bypass mechanism (the 2 options I previously listed). Do not hesitate to provide any guidance to take a decision.

@gmlewis
Copy link
Collaborator

gmlewis commented Jun 22, 2021

My current thought is to not add to the complexity of Client.checkRateLimitBeforeDo() but instead modify only Client.RateLimits() as necessary to implement this change.

I'm fine for you to go ahead and create a PR if you are interested, @sa-spag, and let's see what it looks like.

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 a pull request may close this issue.

2 participants