Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set max number of refreshes before exception #106

Open
coughlinjake opened this issue Jul 3, 2023 · 0 comments
Open

set max number of refreshes before exception #106

coughlinjake opened this issue Jul 3, 2023 · 0 comments

Comments

@coughlinjake
Copy link

This module is awesome, and it's working great!

To detect/prevent issues where the lock seems to be held by a hung block of code, it'd be great if it was possible to set a max number of times the lock could be refreshed.

For example, we just had an issue where we use redis_lock to protect a block of code that generates a shared token, and the token code got hung up:

 [INFO] [redis_client] [lock] LOCKING CACHE KEY 'AUTH_TOKEN_KEY.api.userid'
 [DEBUG] [redis_client] [lock] the lock ttl: 60
 [DEBUG] [redis_client] [lock] ==>ACQUIRING LOCK<== 'AUTH_TOKEN_KEY.api.userid'
 [DEBUG] [__init__] [acquire] Acquiring Lock('lock:AUTH_TOKEN_KEY.api.userid') ...
 [INFO] [__init__] [acquire] Acquired Lock('lock:AUTH_TOKEN_KEY.api.userid').
 [DEBUG] [__init__] [_start_lock_renewer] Starting renewal thread for Lock('lock:AUTH_TOKEN_KEY.api.userid'). Refresh interval: 40.0 seconds.
 [DEBUG] [redis_client] [lock] ==>ACQUIRED LOCK<== on 'AUTH_TOKEN_KEY.api.userid'; YIELDING TO CALLER
 [DEBUG] [auth_caching] [_fetch_cache_key] fetching cache key 'AUTH_TOKEN_KEY.api.userid'
 [DEBUG] [redis_client] [get_key] GETTING CACHE key 'AUTH_TOKEN_KEY.api.userid'
 [DEBUG] [redis_client] [get_key] key 'AUTH_TOKEN_KEY.api.userid' => val 'None'
 [INFO] [auth_caching] [_get_oauth_token] NO cached token => calling super()._get_oauth_token()
 [DEBUG] [__init__] [_lock_renewer] Refreshing Lock('lock:AUTH_TOKEN_KEY.api.userid').
 [DEBUG] [__init__] [_lock_renewer] Refreshing Lock('lock:AUTH_TOKEN_KEY.api.userid').
 [DEBUG] [__init__] [_lock_renewer] Refreshing Lock('lock:AUTH_TOKEN_KEY.api.userid').
 [DEBUG] [__init__] [_lock_renewer] Refreshing Lock('lock:AUTH_TOKEN_KEY.api.userid').
 [DEBUG] [__init__] [_lock_renewer] Refreshing Lock('lock:AUTH_TOKEN_KEY.api.userid').
 [DEBUG] [__init__] [_lock_renewer] Refreshing Lock('lock:AUTH_TOKEN_KEY.api.userid').
 [DEBUG] [__init__] [_lock_renewer] Refreshing Lock('lock:AUTH_TOKEN_KEY.api.userid').
 [DEBUG] [__init__] [_lock_renewer] Refreshing Lock('lock:AUTH_TOKEN_KEY.api.userid').

The "Refreshing Lock" message continues for hours until we explicitly deleted the lock key.

Setting a max number of refreshes would be an easy way to prevent a hung code block from keeping the lock forever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant