Skip to content

Commit 916afcb

Browse files
committed
When SlotNotCoveredError is raised, the cluster topology should be reinitialized as part of error handling and retrying of the commands. (#3621)
1 parent 28964c1 commit 916afcb

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

redis/asyncio/cluster.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -799,10 +799,16 @@ async def _execute_command(
799799
# and try again with the new setup
800800
await self.aclose()
801801
raise
802-
except ClusterDownError:
802+
except (ClusterDownError, SlotNotCoveredError):
803803
# ClusterDownError can occur during a failover and to get
804804
# self-healed, we will try to reinitialize the cluster layout
805805
# and retry executing the command
806+
807+
# SlotNotCoveredError can occur when the cluster is not fully
808+
# initialized or can be temporary issue.
809+
# We will try to reinitialize the cluster topology
810+
# and retry executing the command
811+
806812
await self.aclose()
807813
await asyncio.sleep(0.25)
808814
raise

redis/cluster.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,12 @@ class AbstractRedisCluster:
424424
list_keys_to_dict(["SCRIPT FLUSH"], lambda command, res: all(res.values())),
425425
)
426426

427-
ERRORS_ALLOW_RETRY = (ConnectionError, TimeoutError, ClusterDownError)
427+
ERRORS_ALLOW_RETRY = (
428+
ConnectionError,
429+
TimeoutError,
430+
ClusterDownError,
431+
SlotNotCoveredError,
432+
)
428433

429434
def replace_default_node(self, target_node: "ClusterNode" = None) -> None:
430435
"""Replace the default cluster node.
@@ -1225,13 +1230,19 @@ def _execute_command(self, target_node, *args, **kwargs):
12251230
except AskError as e:
12261231
redirect_addr = get_node_name(host=e.host, port=e.port)
12271232
asking = True
1228-
except ClusterDownError as e:
1233+
except (ClusterDownError, SlotNotCoveredError):
12291234
# ClusterDownError can occur during a failover and to get
12301235
# self-healed, we will try to reinitialize the cluster layout
12311236
# and retry executing the command
1237+
1238+
# SlotNotCoveredError can occur when the cluster is not fully
1239+
# initialized or can be temporary issue.
1240+
# We will try to reinitialize the cluster topology
1241+
# and retry executing the command
1242+
12321243
time.sleep(0.25)
12331244
self.nodes_manager.initialize()
1234-
raise e
1245+
raise
12351246
except ResponseError:
12361247
raise
12371248
except Exception as e:

0 commit comments

Comments
 (0)