Skip to content

When SlotNotCoveredError is raised, the cluster topology should be reinitialized as part of error handling and retrying of the commands. #3621

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 2 commits into from
Apr 29, 2025
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
8 changes: 7 additions & 1 deletion redis/asyncio/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,10 +808,16 @@ async def _execute_command(
# and try again with the new setup
await self.aclose()
raise
except ClusterDownError:
except (ClusterDownError, SlotNotCoveredError):
# ClusterDownError can occur during a failover and to get
# self-healed, we will try to reinitialize the cluster layout
# and retry executing the command

# SlotNotCoveredError can occur when the cluster is not fully
# initialized or can be temporary issue.
# We will try to reinitialize the cluster topology
# and retry executing the command

await self.aclose()
await asyncio.sleep(0.25)
raise
Expand Down
17 changes: 14 additions & 3 deletions redis/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,12 @@ class AbstractRedisCluster:
list_keys_to_dict(["SCRIPT FLUSH"], lambda command, res: all(res.values())),
)

ERRORS_ALLOW_RETRY = (ConnectionError, TimeoutError, ClusterDownError)
ERRORS_ALLOW_RETRY = (
ConnectionError,
TimeoutError,
ClusterDownError,
SlotNotCoveredError,
)

def replace_default_node(self, target_node: "ClusterNode" = None) -> None:
"""Replace the default cluster node.
Expand Down Expand Up @@ -1239,13 +1244,19 @@ def _execute_command(self, target_node, *args, **kwargs):
except AskError as e:
redirect_addr = get_node_name(host=e.host, port=e.port)
asking = True
except ClusterDownError as e:
except (ClusterDownError, SlotNotCoveredError):
# ClusterDownError can occur during a failover and to get
# self-healed, we will try to reinitialize the cluster layout
# and retry executing the command

# SlotNotCoveredError can occur when the cluster is not fully
# initialized or can be temporary issue.
# We will try to reinitialize the cluster topology
# and retry executing the command

time.sleep(0.25)
self.nodes_manager.initialize()
raise e
raise
except ResponseError:
raise
except Exception as e:
Expand Down
Loading