Skip to content

Commit

Permalink
fix(login): fix lock during redis login
Browse files Browse the repository at this point in the history
  • Loading branch information
corenting committed Aug 25, 2024
1 parent 5b6f80a commit 2eab427
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 40 deletions.
12 changes: 8 additions & 4 deletions eddrit/utils/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
]

_valkey_connection_pool = valkey.ConnectionPool.from_url(url=VALKEY_URL)
_valkey_lock_key = "oauth_login_lock"
_valkey_login_lock_key = "oauth_login_lock"
_valkey_check_headers_lock_key = "oauth_check_headers_lock"
_valkey_headers_key = "oauth_headers"


Expand Down Expand Up @@ -119,8 +120,11 @@ def _get_login_headers_from_cache() -> dict[str, Any]:
Get the login headers from cache
"""
valkey_client = valkey.Valkey(connection_pool=_valkey_connection_pool)
with valkey_client.lock(_valkey_lock_key, timeout=20, blocking_timeout=5):
# Check if we have login headers in cache
# Check if we have login headers in cache, with lock if multiple workers
# try to login at same time
with valkey_client.lock(
_valkey_check_headers_lock_key, timeout=20, blocking_timeout=5
):
if not valkey_client.exists(_valkey_headers_key):
oauth_login()

Expand All @@ -136,7 +140,7 @@ def oauth_login() -> None:
logger.debug("Performing OAuth login")
valkey_client = valkey.Valkey(connection_pool=_valkey_connection_pool)

with valkey_client.lock(_valkey_lock_key, timeout=20, blocking_timeout=5):
with valkey_client.lock(_valkey_login_lock_key, timeout=20, blocking_timeout=5):
# Generate identity: unique ID + random user-agent
unique_uuid = str(uuid4())
android_app_version = random.choice(OFFICIAL_ANDROID_APP_VERSIONS) # noqa: S311
Expand Down
3 changes: 1 addition & 2 deletions static/vendors/dashjs/dash.all.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/vendors/videojs/video-js-min.css

Large diffs are not rendered by default.

73 changes: 40 additions & 33 deletions static/vendors/videojs/video.min.js

Large diffs are not rendered by default.

0 comments on commit 2eab427

Please sign in to comment.