Skip to content

Commit a4df6b2

Browse files
authored
When SlotNotCoveredError is raised, the cluster topology should be reinitialized as part of error handling and retrying of the commands. (#3621)
1 parent 4fef1bd commit a4df6b2

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

redis/asyncio/cluster.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,10 +808,16 @@ async def _execute_command(
808808
# and try again with the new setup
809809
await self.aclose()
810810
raise
811-
except ClusterDownError:
811+
except (ClusterDownError, SlotNotCoveredError):
812812
# ClusterDownError can occur during a failover and to get
813813
# self-healed, we will try to reinitialize the cluster layout
814814
# and retry executing the command
815+
816+
# SlotNotCoveredError can occur when the cluster is not fully
817+
# initialized or can be temporary issue.
818+
# We will try to reinitialize the cluster topology
819+
# and retry executing the command
820+
815821
await self.aclose()
816822
await asyncio.sleep(0.25)
817823
raise

redis/cluster.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,12 @@ class AbstractRedisCluster:
410410
list_keys_to_dict(["SCRIPT FLUSH"], lambda command, res: all(res.values())),
411411
)
412412

413-
ERRORS_ALLOW_RETRY = (ConnectionError, TimeoutError, ClusterDownError)
413+
ERRORS_ALLOW_RETRY = (
414+
ConnectionError,
415+
TimeoutError,
416+
ClusterDownError,
417+
SlotNotCoveredError,
418+
)
414419

415420
def replace_default_node(self, target_node: "ClusterNode" = None) -> None:
416421
"""Replace the default cluster node.
@@ -1239,13 +1244,19 @@ def _execute_command(self, target_node, *args, **kwargs):
12391244
except AskError as e:
12401245
redirect_addr = get_node_name(host=e.host, port=e.port)
12411246
asking = True
1242-
except ClusterDownError as e:
1247+
except (ClusterDownError, SlotNotCoveredError):
12431248
# ClusterDownError can occur during a failover and to get
12441249
# self-healed, we will try to reinitialize the cluster layout
12451250
# and retry executing the command
1251+
1252+
# SlotNotCoveredError can occur when the cluster is not fully
1253+
# initialized or can be temporary issue.
1254+
# We will try to reinitialize the cluster topology
1255+
# and retry executing the command
1256+
12461257
time.sleep(0.25)
12471258
self.nodes_manager.initialize()
1248-
raise e
1259+
raise
12491260
except ResponseError:
12501261
raise
12511262
except Exception as e:

0 commit comments

Comments
 (0)