This repository has been archived by the owner on Mar 13, 2023. It is now read-only.
fix: resolve global ratelimit being exceeded #679
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What type of pull request is this?
Description
Resolves #677
Prevents the HTTP client from exceeding the global rate limit. The previous implementation could be exceeded if you fired a lot of requests in quick succession... defeating the point of the limit.
For the base implementation of this, credit should be given to @Bluenix2 in this thread discord/discord-api-docs#5144 (comment). Their implementation mostly works, but as per their own comment; they can still hit global rate limits. The most likely cause of this would be the request landing in different global buckets due to exec time. This can be resolved simply by changing the maximum allowed requests to a number below 50. 49 works, however, this implementation uses 45 to be more conservative.
Through testing, I was unable to hit a 429 Global rate limit. However, as a further safeguard, this also overrides the default
ClientSession.connector
with aTCPConnector
with a hard limit ofglobal_lock.max_requests
(45) active connections.Test Code:
Changes
Checklist
Python 3.10.x