-
Notifications
You must be signed in to change notification settings - Fork 623
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
Ratelimit code seems to fail #1041
Comments
Why do you think the rate limiting code is incorrect? By the looks, this is hitting those rate limits and running out of retries; the error message could definitely be improved to state that instead of failing on the body read. |
Also, if the DNSControl tests are always run from the same account you can provide me with the account ID and I can take a look at bumping the allowed rate limits. It won't mean you can run it nonstop so you'll need to limit real API calls to when they are actually needed. |
Thank you for the offer to increase the allowed rate. I may take you up on that offer but first I'd like to make sure the rate limiting code works, which is easier to do at the lower limit. (It could be a bug on my side too!) To be clear, I'm not 100% certain there is a bug. I'm still trying to understand the code. In particular, in this code
|
from a brief look at the code, this is inside of a block that checks if
from there, it attempts to read the body but also sets i feel like the logic here is a little odd however, the more likely scenario is that the rate limited condition is just throwing the wrong error message. this code is rather confusing to follow which is why i swapped out this for retryable-http for the experimental client in #977. tbh, i wouldn't mind doing the same here however, i'd have to first unpick the web that it is to make sure we don't break anything else too. |
the following patch propagates the out of retries message as expected which might be the clearer solution here diff --git cloudflare.go cloudflare.go
index b8bd301..5c17da0 100644
--- cloudflare.go
+++ cloudflare.go
@@ -251,6 +251,10 @@ func (api *API) makeRequestWithAuthTypeAndHeaders(ctx context.Context, method, u
// retry if the server is rate limiting us or if it failed
// assumes server operations are rolled back on failure
if respErr != nil || resp.StatusCode == http.StatusTooManyRequests || resp.StatusCode >= 500 {
+ if resp.StatusCode == http.StatusTooManyRequests {
+ respErr = errors.New("ran out of rate limit retries")
+ }
+
// if we got a valid http response, try to read body so we can reuse the connection
// see https://golang.org/pkg/net/http/#Client.Do
if respErr == nil {
|
Yes, that would be an improvement! I have some other suggestions:
|
no but at the moment, if the API 5xx's it is very unlikely to be parsable. i think it's safe (for now) to leave this. there is work to address this but it's not super straight forward due to a few constraints we are working on.
the problem with the retries is that the backoff basically doubles each retry so but 3 retries, you're over 10s in waiting for a response. for most, this isn't a great experience as if you don't have the logger in place getting updates, you just think it is sitting there not working. you can control this individually using the the other factor to consider here is that the rate limit is per 5 minute window so retrying for 10-30s may not solve it and i doubt anyone would want to sit there for up to 4 minutes 59 seconds waiting for it to retry. |
have made this clearer with #1043 |
This functionality has been released in v0.47.0. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
Confirmation
cloudflare-go version
v0.46.0
Go environment
Expected output
I'm not entirely sure if I'm going in the right direction and can use some help.
This module is used by DNSControl, which seems to fail its integration tests when ratelimiting kicks in:
https://app.circleci.com/pipelines/github/StackExchange/dnscontrol/1335/workflows/407541cf-dcf9-416e-8aea-799e1505050d/jobs/10332
I think I'm seeing a failure that I think is related to the ratelimiting code added in e1f3c42 by @benjvi
https://github.com/cloudflare/cloudflare-go/blob/master/cloudflare.go#L260
My question is:
On line 260, why do we always set
respErr
instead of only setting it if there is an error?Actual output
Code demonstrating the issue
https://github.com/StackExchange/dnscontrol
Steps to reproduce
FYI: I apologize for the incomplete bug report. I'm recording what I have now and will add to it as I research it more.
References
Bug in DNSControl: StackExchange/dnscontrol#1711
CC: @tresni
The text was updated successfully, but these errors were encountered: