Skip to content

Commit b12b6f0

Browse files
petyaslavovaManelCoutinhoSensei
authored andcommitted
Prevent RuntimeError while reinitializing clusters - sync and async (redis#3633)
* Prevent RuntimeError while reinitializing clusters - sync and async * Applying copilot's review comments
1 parent 9dec908 commit b12b6f0

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

redis/asyncio/cluster.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,9 @@ async def initialize(self) -> None:
13151315
startup_nodes_reachable = False
13161316
fully_covered = False
13171317
exception = None
1318-
for startup_node in self.startup_nodes.values():
1318+
# Convert to tuple to prevent RuntimeError if self.startup_nodes
1319+
# is modified during iteration
1320+
for startup_node in tuple(self.startup_nodes.values()):
13191321
try:
13201322
# Make sure cluster mode is enabled on this node
13211323
try:

redis/cluster.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1674,7 +1674,9 @@ def initialize(self):
16741674
fully_covered = False
16751675
kwargs = self.connection_kwargs
16761676
exception = None
1677-
for startup_node in self.startup_nodes.values():
1677+
# Convert to tuple to prevent RuntimeError if self.startup_nodes
1678+
# is modified during iteration
1679+
for startup_node in tuple(self.startup_nodes.values()):
16781680
try:
16791681
if startup_node.redis_connection:
16801682
r = startup_node.redis_connection

0 commit comments

Comments
 (0)