Merge pull request #5936 from FinnStutzenstein/redisTimeoutErrors

Attempt on handling timeout errors
This commit is contained in:
Finn Stutzenstein 2021-03-04 09:09:38 +01:00 committed by GitHub
commit 265145f001
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,5 @@
# type: ignore # type: ignore
from time import sleep
from asgiref.sync import async_to_sync from asgiref.sync import async_to_sync
from django.conf import settings from django.conf import settings
@ -33,7 +34,16 @@ class SessionStore(SessionBase):
return salted_hmac(key_salt, value).hexdigest() return salted_hmac(key_salt, value).hexdigest()
def load(self): def load(self):
retries = 0
while True:
try:
return async_to_sync(self._load)() 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 def _load(self):
async with get_connection(read_only=True) as redis: async with get_connection(read_only=True) as redis: