From 78c05cb7bdaa714d814c3a174e30da0f8c51ccca Mon Sep 17 00:00:00 2001 From: Shlomi Matichin Date: Sun, 12 May 2019 15:50:48 +0300 Subject: [PATCH] Bugfix: do not wait 30 seconds for expiry, trust the ttl --- python_dynamodb_lock/python_dynamodb_lock.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/python_dynamodb_lock/python_dynamodb_lock.py b/python_dynamodb_lock/python_dynamodb_lock.py index 5dbeec9a..412626ea 100644 --- a/python_dynamodb_lock/python_dynamodb_lock.py +++ b/python_dynamodb_lock/python_dynamodb_lock.py @@ -448,9 +448,8 @@ def acquire_lock(self, last_record_version_number) # if the record_version_number has not changed for more than _lease_duration period, # it basically means that the owner thread/process has died. - last_version_elapsed_time = time.monotonic() - last_version_fetch_time - if last_version_elapsed_time > existing_lock.lease_duration: - logger.warning('Existing lock\'s lease has expired: %s', str(existing_lock)) + if existing_lock.expiry_time < time.time(): + logger.warning('Existing lock\'s lease has expired: %s (%s)', str(existing_lock), time.time()) self._overwrite_existing_lock_in_dynamodb(new_lock, last_record_version_number) logger.debug('Added to the DDB. Adding to in-memory map: %s', new_lock.unique_identifier) new_lock.status = DynamoDBLock.LOCKED