Skip to content

Commit fb547af

Browse files
committed
When SlotNotCoveredError is raised, the cluster topology should be reinitialized as part of error handling and retrying of the commands. (redis#3621)
1 parent 8dadea2 commit fb547af

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
@@ -818,10 +818,16 @@ async def _execute_command(
818818
# and try again with the new setup
819819
await self.aclose()
820820
raise
821-
except ClusterDownError:
821+
except (ClusterDownError, SlotNotCoveredError):
822822
# ClusterDownError can occur during a failover and to get
823823
# self-healed, we will try to reinitialize the cluster layout
824824
# and retry executing the command
825+
826+
# SlotNotCoveredError can occur when the cluster is not fully
827+
# initialized or can be temporary issue.
828+
# We will try to reinitialize the cluster topology
829+
# and retry executing the command
830+
825831
await self.aclose()
826832
await asyncio.sleep(0.25)
827833
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)