twilight icon indicating copy to clipboard operation
twilight copied to clipboard

Pre-emptively halt requests to not encounter global ratelimit

Open rxdn opened this issue 4 years ago • 3 comments

From my understanding from our discussion in Discord, ~~global ratelimits are not handled by the http module's ratelimiting function.~~ more than the global ratelimit bucket's worth of requests may be sent at once, due to not being able to know the size and reset rate of the ratelimit bucket.

Discord assigns everyone a global cap of 50 requests per second, which can be increased after the requirements for large sharding are met or under exceptional circumstances, so it would be safe to impose a default limit of 50, unless the user provides their own limit to override with.

*EDIT: corrected first statement. Additionally, this means we will be hard-coding information that Discord does not provide, so we need to consider if this is something we want to do or, at the least, provide some sort of "cap" on in-flight requests.

rxdn avatar Dec 26 '20 22:12 rxdn

There is an invalid request limit of 10_000/10 minutes that will ban you for an hour when you reach it. Maybe twilight should stop sending requests after e.g. 9_999 invalid requests to prevent getting globally rate limited for one hour too.

itohatweb avatar Nov 21 '21 18:11 itohatweb

Wouldn't hard-coding, even an over-writable, value would go against Discord's recommendations of using dynamic ratelimits? The cloudflare limit is however a sound exception

vilgotf avatar May 20 '22 20:05 vilgotf

I think hardcoding but allowing to override the global rate limit is fine since it's explicitly documented at https://discord.com/developers/docs/topics/rate-limits#global-rate-limit

Cloudflare ones could be nice if we ensure it excludes the shared rate limits

AEnterprise avatar May 21 '22 07:05 AEnterprise