aio-libs-abandoned / aioredis-py

asyncio (PEP 3156) Redis support
https://aioredis.readthedocs.io/
MIT License
2.3k stars 336 forks source link

"aioredis.exceptions.ConnectionError: max number of clients reached" When my website gets lots of requests #1179

Closed Nebulizer1213 closed 2 years ago

Nebulizer1213 commented 2 years ago

Describe the bug

When I dos my website I get this error aioredis.exceptions.ConnectionError: max number of clients reached. I do not get this error when using the non async redis library.

To Reproduce

code : https://pastecord.com/pozywivufa.py

Expected behavior

I would expect this to ratelimit the requests from the dos attack.

Logs/tracebacks

`Error handling request
Traceback (most recent call last):
  File "C:\Users\fixin\PycharmProjects\aiohttp-ratelimiter\venv\lib\site-packages\aiohttp\web_protocol.py", line 422, in _handle_request
    resp = await self._request_handler(request)
  File "C:\Users\fixin\PycharmProjects\aiohttp-ratelimiter\venv\lib\site-packages\aiohttp\web_app.py", line 499, in _handle
    resp = await handler(request)
  File "C:\Users\fixin\PycharmProjects\aiohttp-ratelimiter\aiohttplimiter\redis_limiter.py", line 43, in wrapper
    nc = await self.db.get(db_key)
  File "C:\Users\fixin\PycharmProjects\aiohttp-ratelimiter\venv\lib\site-packages\aioredis\client.py", line 1061, in execute_command
    conn = self.connection or await pool.get_connection(command_name, **options)
  File "C:\Users\fixin\PycharmProjects\aiohttp-ratelimiter\venv\lib\site-packages\aioredis\connection.py", line 1359, in get_connection
    await connection.connect()
  File "C:\Users\fixin\PycharmProjects\aiohttp-ratelimiter\venv\lib\site-packages\aioredis\connection.py", line 661, in connect
    await self.on_connect()
  File "C:\Users\fixin\PycharmProjects\aiohttp-ratelimiter\venv\lib\site-packages\aioredis\connection.py", line 726, in on_connect
    auth_response = await self.read_response()
  File "C:\Users\fixin\PycharmProjects\aiohttp-ratelimiter\venv\lib\site-packages\aioredis\connection.py", line 854, in read_response
    response = await self._parser.read_response()
  File "C:\Users\fixin\PycharmProjects\aiohttp-ratelimiter\venv\lib\site-packages\aioredis\connection.py", line 383, in read_response
    raise error
aioredis.exceptions.ConnectionError: max number of clients reached
`

Python Version

$ python --version
3.9.7

aioredis Version

$ python -m pip show aioredis
2.0

Additional context

No response

Code of Conduct

Andrew-Chen-Wang commented 2 years ago

this may be a duplicate of #1173. Additionally, IIRC @abrookins also had this issue and may have been looking into it.

I'll also play around after my exams.

Nebulizer1213 commented 2 years ago

ok thanks

Nebulizer1213 commented 2 years ago

Any updates on this?

Andrew-Chen-Wang commented 2 years ago

No, do you have the same problem is you use aredis? Perhaps they managed to fix the logic issues.

Nebulizer1213 commented 2 years ago

I have the problem with aredis

abrookins commented 2 years ago

Hello and thanks for your bug report! Nothing jumps out at me while reading your code. Can you give a minimum reproducible example showing how you use the rate limiter and how you're initiating the load test, so I can reproduce?

On Fri, Nov 5, 2021 at 6:21 PM Nebulizer1213 @.***> wrote:

I have the problem with aredis

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/aio-libs/aioredis-py/issues/1179#issuecomment-962313763, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAXXHUDXAYVWWDNHS2BD43UKSGITANCNFSM5GMMRVAA .

Nebulizer1213 commented 2 years ago

The code has been updated since I made this issue. The newer version is on pypi. It's called aiohttp-ratelimiter. Examples of how to use it can be found in the README on my repo. The bug happens when I dos the website.