Skip to content

Prevent RuntimeError while reinitializing clusters - sync and async #3633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion redis/asyncio/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,9 @@ async def initialize(self) -> None:
startup_nodes_reachable = False
fully_covered = False
exception = None
for startup_node in self.startup_nodes.values():
# Convert to tuple to prevent RuntimeError if self.startup_nodes
# is modified during iteration
for startup_node in tuple(self.startup_nodes.values()):
try:
# Make sure cluster mode is enabled on this node
try:
Expand Down
4 changes: 3 additions & 1 deletion redis/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -1674,7 +1674,9 @@ def initialize(self):
fully_covered = False
kwargs = self.connection_kwargs
exception = None
for startup_node in self.startup_nodes.values():
# Convert to tuple to prevent RuntimeError if self.startup_nodes
# is modified during iteration
for startup_node in tuple(self.startup_nodes.values()):
try:
if startup_node.redis_connection:
r = startup_node.redis_connection
Expand Down
Loading