Add retries to connections in Sentinel Pools
@@ -37,7 +37,7 @@ class SentinelManagedConnection(Connection):
if str_if_bytes(self.read_response()) != "PONG":
raise ConnectionError("PING failed")
- def connect(self):
+ def _connect_retry(self):
if self._sock:
return # already connected
if self.connection_pool.is_master:
@@ -50,6 +50,12 @@ class SentinelManagedConnection(Connection):
continue
raise SlaveNotFoundError # Never be here
+ def connect(self):
+ return self.retry.call_with_retry(
+ self._connect_retry,
+ lambda error: None,
+ )
+
def read_response(self, disable_decoding=False):
try:
return super().read_response(disable_decoding=disable_decoding)
