From f5b60f2909c6683345ae0f1070e84e40c41af5ad Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 5 Sep 2024 10:26:14 -0500 Subject: Synchronise token refreshing. When running flask with multiple threads/workers, as happens when using gunicorn, there is a potential for more than one thread running with an expired token, leading to multiple uncoordinated token refreshes. This commit coordinates the threads in the case there is need to refresh a token, ensuring only one thread does the token refresh. --- uploader/session.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'uploader/session.py') diff --git a/uploader/session.py b/uploader/session.py index 019d959..399f28c 100644 --- a/uploader/session.py +++ b/uploader/session.py @@ -103,3 +103,16 @@ def set_auth_server_jwks(keyset: KeySet) -> KeySet: } }) return keyset + + +def toggle_token_refreshing(): + """Toggle the state of the token_refreshing variable.""" + _session = session_info() + return save_session_info({ + **_session, + "token_refreshing": not _session.get("token_refreshing", False)}) + + +def is_token_refreshing(): + """Returns whether the token is being refreshed or not.""" + return session_info().get("token_refreshing", False) -- cgit v1.2.3