Description
valkey-py 6.1.0
appears to handle asyncio cluster connections uncleanly. As a result, I am seeing crashes due to Unclosed ClusterNode object
errors being raised in the event loop.
I assume this is what triggers it:
-
In
valkey.asyncio.cluster.NodesManager.initialize()
,.set_nodes()
is called withremove_old=True
argument, if certain conditions are satisfied:
valkey-py/valkey/asyncio/cluster.py
Line 1406 in ca5c7c5
-
.set_nodes()
creates asyncio tasks to disconnect any 'old' cluster nodes, but fails to await those tasks (the noqa pragma might be telling):
valkey-py/valkey/asyncio/cluster.py
Lines 1199 to 1215 in ca5c7c5
-
The finalizer of
valkey.asyncio.cluster.ClusterNode
checks for any connections that have not been disconnected yet. Since the disconnection tasks from 2. are not awaited, the failure is triggered:
valkey-py/valkey/asyncio/cluster.py
Lines 1022 to 1036 in ca5c7c5
As a potential solution, set_nodes()
could be made into a coroutine function that awaits the disconnect tasks before returning.
Client: valkey-py 6.1.0, CPython 3.13.2, containerized Linux on arm64
Database: Amazon ElastiCache for Valkey 8.0.1, t4g based instances, cluster mode enabled