Skip to content

set max number of refreshes before exception #106

@coughlinjake

Description

@coughlinjake

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions