andersfylling / disgord

Go module for interacting with the documented Discord's bot interface; Gateway, REST requests and voice
BSD 3-Clause "New" or "Revised" License
496 stars 70 forks source link

Rate limit exceeded due to shared buckets #391

Open meooow25 opened 3 years ago

meooow25 commented 3 years ago

Describe the bug A rate limit exceeded error can occur if a certain endpoint shares the rate limit bucket with another endpoint but disgord doesn't know it yet. For example, if I react on a message and immediately unreact, the unreact fails because it shares the bucket with react. Example bot: gist.

I'm hesitant to call this a bug because I understand that this is how Discord works and it is not possible to know the bucket in advance, but it would be nice if the request could be auto-retried if, for instance, it fails due to 429 and its bucket was previously unknown. I will have to manually implement a retry anyway if disgord doesn't do it.

andersfylling commented 3 years ago

I've actually started allowing people to inject anything that implements the http Do interface. So you can use something like heimdall. The only issue right now, is that the rate limit logic then needs to be a http.RoundTripper implementation.

So as soon as a super simple, round tripper algorithm is implemented, this should be fixed if you use something like https://github.com/gojek/heimdall.

meooow25 commented 3 years ago

I've actually started allowing people to inject anything that implements the http Do interface.

I see that the client config accepts a http.Client specifically (and not a Do interface), am I missing something?

Thanks for the http.RoundTripper suggestion, using a http.Client with some form of a retrying RoundTripper implementation is an option. I can try to see if it works. If disgord allows Do interfaces I would be able to use a retrying Client instead.

I don't think heimdall is particularly useful here, even if disgord allows Do interfaces, because it does not detect 429s as errors to retry on and I see no way to configure it to do so.

Edit: I just realized that disgord accepts Do interfaces at head

andersfylling commented 3 years ago

The Do support has not been released yet. It only exist in the development branch.