Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rate limits occasionally lead to errors. #9418

Open
3 tasks done
JacksonBarker opened this issue May 20, 2023 · 2 comments
Open
3 tasks done

Rate limits occasionally lead to errors. #9418

JacksonBarker opened this issue May 20, 2023 · 2 comments
Labels
unconfirmed bug A bug report that needs triaging

Comments

@JacksonBarker
Copy link

JacksonBarker commented May 20, 2023

Summary

Occasionally, rate limits result in errors instead of warnings. In this case the request is not rescheduled.

Reproduction Steps

For testing, a simple bot is created that will await message.delete() when on_message(message) is called.
Users will produce simulated spam in an attempt to overwhelm the API rate limit.

Minimal Reproducible Code

@client.event
    async def on_message(message: discord.Message):
        await message.delete()

Expected Results

The bot will re-schedule all DELETE requests that are missed while the bot was rate limited
WARNING discord.http We are being rate limited. DELETE https://discord.com/api/v10/channels/XXXXXXXXXX/messages/XXXXXXXXXX responded with 429. Retrying in 0.XX seconds.

Actual Results

For some few messages, instead of deleting the message, the following error message is displayed

ERROR    discord.client Ignoring exception in on_message
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/discord/client.py", line 441, in _run_event
     await coro(*args, **kwargs)
   File "//./bot.py", line 20, in on_message
     await message.delete()
   File "/usr/local/lib/python3.10/site-packages/discord/message.py", line 841, in delete
     await self._state.http.delete_message(self.channel.id, self.id)
   File "/usr/local/lib/python3.10/site-packages/discord/http.py", line 759, in request
     raise HTTPException(response, data)
 discord.errors.HTTPException: 429 Too Many Requests (error code: 0): You are being rate limited.

Intents

discord.Intents.all()

System Information

- Python v3.10.11-final
- discord.py v2.2.3-final
- aiohttp v3.8.4
- system info: Linux 5.15.0-71-generic #78-Ubuntu SMP Tue Apr 18 09:00:29 UTC 2023

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

No response

@JacksonBarker JacksonBarker added the unconfirmed bug A bug report that needs triaging label May 20, 2023
@mikeshardmind
Copy link
Contributor

mikeshardmind commented May 20, 2023

This sounds like a bad idea. If you're consistently reaching the only code path that can have this happen, you're getting a 429 without at least some of the ratelimit info, see:

discord.py/discord/http.py

Lines 677 to 680 in e870bb1

if response.status == 429:
if not response.headers.get('Via') or isinstance(data, str):
# Banned by Cloudflare more than likely.
raise HTTPException(response, data)

And it's likely a Cloudflare 429 from other times people have hit this. There's no good way to reschedule this even if it did make sense at that point, and it's better to error out when you've got a pathological case that got picked up by cloudflare than to keep trying anyhow.

@JacksonBarker
Copy link
Author

JacksonBarker commented May 20, 2023

My concern is that I was able to trigger this condition with a single user (On a different network/ IP). Using a bot for moderation, it is safe to assume that even a server with a dozen or so online users would overwhelm the bot easily. That doesn't make sense, how are other unverified bots able to avoid this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unconfirmed bug A bug report that needs triaging
Projects
None yet
Development

No branches or pull requests

2 participants