-
Notifications
You must be signed in to change notification settings - Fork 335
Redis.close() doesn't close connection pool created in __init__ #1103
Comments
Also ran into this issue. Thanks for the workaround. Waiting for proper fix upstream. |
Please let me know if master branch has resolved this issue. |
Not really. Instead of
we now get
I think this change was supposed to be in the 2.0.1 release, but that hasn't been published to the PyPI yet. |
Sorry! Thanks for telling me this! 2.0.1 has now been released. Can you provide code to reproduce? |
I'm currently trying to write a minimal reproducing example that does not involve the Asphalt framework. |
Here: import asyncio
import aioredis
async def main():
redis = aioredis.from_url('redis://localhost:63790')
await redis.set('key', b'value')
await redis.close()
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.stop()
loop.close() |
Explicitly calling |
tl;dr #1256 should remedy this issue of cleanup where redis-py has cleanup in Yes take a look at https://github.com/aio-libs/aioredis-py/blob/56d6b325ee246a3eb0fc8bb6803247c86bb2f494/aioredis/client.py#L863 where a user might want control over a connection pool by passing in their own through Redis's constructor. The reason this is not done but works fine on redis-py is because all Connection classes do a disconnect on |
For the record, I think redis-py is also in the wrong in relying on the GC for this, even if that works out for them. Different GC behavior on different Python implementations means that there is no telling when the connections are going to be closed. |
Still reproducible on 2.0.1 and master. |
Yes #1256 had not been merged yet. I am migrating this repo to redis-py with the fix since I am unable to merge anything in this github org; I'd expect redis py with asyncio to come out next month at best. |
Cannot reproduce on |
This results in delayed cleanup via
Connection.__del__
that causes various errors. Circular references in aioredis make it harder to debug. The problem is especially clearly seen when testing with pytest-asyncio that uses a separate event loop. Just upgrading from aioredis 1.3.1 to 2.0.0 leads to the following errors in setup for random test after the test that creates aioredis client:Here the client is created with one loop and creates transport bound to it, then
__del__
is called when some other loop is running causing this transport to close. But this transport uses the loop stored when it's created, which is already closed.With
gc.collect()
after each test it becomes much simpler:The workaround is simple:
The text was updated successfully, but these errors were encountered: