mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-07 20:28:38 +00:00
Fix rate limit handling with retry_after precision change
This commit is contained in:
parent
a6f7213c89
commit
1f74b051a8
@ -224,7 +224,7 @@ class HTTPClient:
|
|||||||
fmt = 'We are being rate limited. Retrying in %.2f seconds. Handled under the bucket "%s"'
|
fmt = 'We are being rate limited. Retrying in %.2f seconds. Handled under the bucket "%s"'
|
||||||
|
|
||||||
# sleep a bit
|
# sleep a bit
|
||||||
retry_after = data['retry_after'] / 1000.0
|
retry_after: float = data['retry_after'] # type: ignore
|
||||||
log.warning(fmt, retry_after, bucket)
|
log.warning(fmt, retry_after, bucket)
|
||||||
|
|
||||||
# check if it's a global rate limit
|
# check if it's a global rate limit
|
||||||
@ -263,6 +263,7 @@ class HTTPClient:
|
|||||||
except OSError as e:
|
except OSError as e:
|
||||||
# Connection reset by peer
|
# Connection reset by peer
|
||||||
if tries < 4 and e.errno in (54, 10054):
|
if tries < 4 and e.errno in (54, 10054):
|
||||||
|
await asyncio.sleep(1 + tries * 2)
|
||||||
continue
|
continue
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ class AsyncWebhookAdapter:
|
|||||||
|
|
||||||
remaining = response.headers.get('X-Ratelimit-Remaining')
|
remaining = response.headers.get('X-Ratelimit-Remaining')
|
||||||
if remaining == '0' and response.status != 429:
|
if remaining == '0' and response.status != 429:
|
||||||
delta = utils._parse_ratelimit_header(response.headers)
|
delta = utils._parse_ratelimit_header(response)
|
||||||
log.debug(
|
log.debug(
|
||||||
'Webhook ID %s has been pre-emptively rate limited, waiting %.2f seconds', webhook_id, delta
|
'Webhook ID %s has been pre-emptively rate limited, waiting %.2f seconds', webhook_id, delta
|
||||||
)
|
)
|
||||||
@ -178,9 +178,10 @@ class AsyncWebhookAdapter:
|
|||||||
if not response.headers.get('Via'):
|
if not response.headers.get('Via'):
|
||||||
raise HTTPException(response, data)
|
raise HTTPException(response, data)
|
||||||
|
|
||||||
retry_after = data['retry_after'] / 1000.0 # type: ignore
|
retry_after: float = data['retry_after'] # type: ignore
|
||||||
log.warning('Webhook ID %s is rate limited. Retrying in %.2f seconds', webhook_id, retry_after)
|
log.warning('Webhook ID %s is rate limited. Retrying in %.2f seconds', webhook_id, retry_after)
|
||||||
await asyncio.sleep(retry_after)
|
await asyncio.sleep(retry_after)
|
||||||
|
continue
|
||||||
|
|
||||||
if response.status >= 500:
|
if response.status >= 500:
|
||||||
await asyncio.sleep(1 + attempt * 2)
|
await asyncio.sleep(1 + attempt * 2)
|
||||||
@ -195,6 +196,7 @@ class AsyncWebhookAdapter:
|
|||||||
|
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if attempt < 4 and e.errno in (54, 10054):
|
if attempt < 4 and e.errno in (54, 10054):
|
||||||
|
await asyncio.sleep(1 + attempt * 2)
|
||||||
continue
|
continue
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ class WebhookAdapter:
|
|||||||
|
|
||||||
remaining = response.headers.get('X-Ratelimit-Remaining')
|
remaining = response.headers.get('X-Ratelimit-Remaining')
|
||||||
if remaining == '0' and response.status_code != 429:
|
if remaining == '0' and response.status_code != 429:
|
||||||
delta = utils._parse_ratelimit_header(response.headers)
|
delta = utils._parse_ratelimit_header(response)
|
||||||
log.debug(
|
log.debug(
|
||||||
'Webhook ID %s has been pre-emptively rate limited, waiting %.2f seconds', webhook_id, delta
|
'Webhook ID %s has been pre-emptively rate limited, waiting %.2f seconds', webhook_id, delta
|
||||||
)
|
)
|
||||||
@ -169,9 +169,10 @@ class WebhookAdapter:
|
|||||||
if not response.headers.get('Via'):
|
if not response.headers.get('Via'):
|
||||||
raise HTTPException(response, data)
|
raise HTTPException(response, data)
|
||||||
|
|
||||||
retry_after = data['retry_after'] / 1000.0 # type: ignore
|
retry_after: float = data['retry_after'] # type: ignore
|
||||||
log.warning('Webhook ID %s is rate limited. Retrying in %.2f seconds', webhook_id, retry_after)
|
log.warning('Webhook ID %s is rate limited. Retrying in %.2f seconds', webhook_id, retry_after)
|
||||||
time.sleep(retry_after)
|
time.sleep(retry_after)
|
||||||
|
continue
|
||||||
|
|
||||||
if response.status_code >= 500:
|
if response.status_code >= 500:
|
||||||
time.sleep(1 + attempt * 2)
|
time.sleep(1 + attempt * 2)
|
||||||
@ -186,6 +187,7 @@ class WebhookAdapter:
|
|||||||
|
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if attempt < 4 and e.errno in (54, 10054):
|
if attempt < 4 and e.errno in (54, 10054):
|
||||||
|
time.sleep(1 + attempt * 2)
|
||||||
continue
|
continue
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user