Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/alya/more-retries-when-db-is-loc…
Browse files Browse the repository at this point in the history
…ked' into develop
  • Loading branch information
AlyaGomaa committed Dec 6, 2023
2 parents 909b27b + d7f0c52 commit b06a56b
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions slips_files/core/database/redis_db/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,13 @@ class RedisDB(IoCHandler, AlertHandler, ProfileHandler, IObservable):
first_flow = True
# to make sure we only detect and store the user's localnet once
is_localnet_set = False
# in case of redis ConnectionErrors, this is how long we'll wait in seconds before retrying.
# in case of redis ConnectionErrors, this is how long we'll wait in
# seconds before retrying.
# this will increase exponentially each retry
backoff = 15
# try to reconnect to redis 3 times in case of connection errors before terminating
max_retries = 3
backoff = 0.1
# try to reconnect to redis this amount of times in case of connection
# errors before terminating
max_retries = 150
# to keep track of connection retries. once it reaches max_retries, slips will terminate
connection_retry = 0

Expand Down Expand Up @@ -341,10 +343,12 @@ def get_message(self, channel, timeout=0.0000001):
self.publish_stop()
self.print(f'Stopping slips due to redis.exceptions.ConnectionError: {ex}', 1, 1)
else:
# retry to connect after backing off for a while
self.print(f"redis.exceptions.ConnectionError: "
f"retrying to connect in {self.backoff}s. "
f"Retries to far: {self.connection_retry}", 0, 1)
# don't log this each retry
if self.connection_retry % 10 == 0:
# retry to connect after backing off for a while
self.print(f"redis.exceptions.ConnectionError: "
f"retrying to connect in {self.backoff}s. "
f"Retries to far: {self.connection_retry}", 0, 1)
time.sleep(self.backoff)
self.backoff = self.backoff * 2
self.connection_retry += 1
Expand Down

0 comments on commit b06a56b

Please sign in to comment.