Browse Source

Use the longest reset_at value on shared 429

pull/10287/head
imp 2 months ago
committed by GitHub
parent
commit
8de2b6db55
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 7
      discord/http.py

7
discord/http.py

@ -392,14 +392,15 @@ class Ratelimit:
self.reset_at = 0.0
def update(self, response: aiohttp.ClientResponse, data: Union[Dict[str, Any], str]) -> bool:
# Shared scope 429 has longer "reset_at", determined using the retry-after field
limit = int(response.headers['X-Ratelimit-Limit'])
reset_at = self.http.loop.time() + (float(response.headers['X-Ratelimit-Reset']) - time.time())
# Shared scope (which only appears on 429s) could have a longer "reset_at".
if response.headers.get('X-RateLimit-Scope') == 'shared':
reset_at = self.http.loop.time() + data['retry_after'] # type: ignore
reset_at = max(reset_at, self.http.loop.time() + data['retry_after']) # type: ignore
remaining = 0
else:
# Consider a lower remaining value because updates can be out of order, so self.outgoing is used
reset_at = self.http.loop.time() + (float(response.headers['X-Ratelimit-Reset']) - time.time())
remaining = min(int(response.headers['X-Ratelimit-Remaining']), limit - self.outgoing)
# The checks below combats out-of-order responses and alternating sub ratelimits.

Loading…
Cancel
Save