Skip to content

Commit 5b46430

Browse files
Hold references to ClusterNode disconnect task (#3826)
* Hold references to ClusterNode disconnect task * Fix linters --------- Co-authored-by: petyaslavova <petya.slavova@redis.com>
1 parent 74cbc8e commit 5b46430

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

redis/asyncio/cluster.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,7 @@ class NodesManager:
14171417
__slots__ = (
14181418
"_dynamic_startup_nodes",
14191419
"_event_dispatcher",
1420+
"_background_tasks",
14201421
"connection_kwargs",
14211422
"default_node",
14221423
"nodes_cache",
@@ -1450,6 +1451,7 @@ def __init__(
14501451
self.read_load_balancer = LoadBalancer()
14511452
self._initialize_lock: asyncio.Lock = asyncio.Lock()
14521453

1454+
self._background_tasks: Set[asyncio.Task] = set()
14531455
self._dynamic_startup_nodes: bool = dynamic_startup_nodes
14541456
if event_dispatcher is None:
14551457
self._event_dispatcher = EventDispatcher()
@@ -1491,7 +1493,11 @@ def set_nodes(
14911493
# not to wait for the disconnects
14921494
removed_node = old.pop(name)
14931495
removed_node.update_active_connections_for_reconnect()
1494-
asyncio.create_task(removed_node.disconnect_free_connections()) # noqa
1496+
task = asyncio.create_task(
1497+
removed_node.disconnect_free_connections()
1498+
)
1499+
self._background_tasks.add(task)
1500+
task.add_done_callback(self._background_tasks.discard)
14951501

14961502
for name, node in new.items():
14971503
if name in old:

0 commit comments

Comments
 (0)