From 39fb2fadec6cbfbf5fa7d34e8cfccc4d5187215e Mon Sep 17 00:00:00 2001 From: Finn Stutzenstein Date: Thu, 4 Mar 2021 08:43:40 +0100 Subject: [PATCH] Attempt on handling timeout errors This code retries to load sessions three times. If not an error will be thrown. There are other solutions (Like not throwing the error), but I would like to see errors in production usage to see, if this helps or not. --- server/openslides/utils/sessions.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server/openslides/utils/sessions.py b/server/openslides/utils/sessions.py index c2d6af15a..a30acd541 100644 --- a/server/openslides/utils/sessions.py +++ b/server/openslides/utils/sessions.py @@ -1,4 +1,5 @@ # type: ignore +from time import sleep from asgiref.sync import async_to_sync from django.conf import settings @@ -33,7 +34,16 @@ class SessionStore(SessionBase): return salted_hmac(key_salt, value).hexdigest() def load(self): - return async_to_sync(self._load)() + retries = 0 + while True: + try: + return async_to_sync(self._load)() + except TimeoutError as e: + if retries < 3: + sleep(0.1) + else: + raise e + retries += 1 async def _load(self): async with get_connection(read_only=True) as redis: