Skip to content

Commit 74d1332

Browse files
committed
print a log when lock cannot be released
1 parent 0855922 commit 74d1332

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

packages/service-library/src/servicelib/redis/_decorators.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
R = TypeVar("R")
2424

2525
_EXCLUSIVE_TASK_NAME: Final[str] = "exclusive/{module_name}.{func_name}"
26-
_EXCLUSIVE_AUTO_EXTEND_TASK_NAME: Final[
27-
str
28-
] = "exclusive/autoextend_lock_{redis_lock_key}"
26+
_EXCLUSIVE_AUTO_EXTEND_TASK_NAME: Final[str] = (
27+
"exclusive/autoextend_lock_{redis_lock_key}"
28+
)
2929

3030

3131
@periodic(interval=DEFAULT_LOCK_TTL / 2, raise_on_error=True)
@@ -134,10 +134,15 @@ async def _wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
134134
assert len(lock_lost_errors.exceptions) == 1 # nosec
135135
raise lock_lost_errors.exceptions[0] from eg
136136
finally:
137-
with contextlib.suppress(redis.exceptions.LockNotOwnedError):
137+
try:
138138
# in the case where the lock would have been lost,
139139
# this would raise again and is not necessary
140140
await lock.release()
141+
except redis.exceptions.LockNotOwnedError:
142+
_logger.exception(
143+
"Unexpected error with lock '%s', cannot release it",
144+
redis_lock_key,
145+
)
141146

142147
return _wrapper
143148

0 commit comments

Comments
 (0)