Skip to content

Commit c92c2ac

Browse files
committed
@pcrespov review: use create_troubleshotting_log_kwargs
1 parent ab0a64e commit c92c2ac

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import asyncio
2-
import contextlib
32
import functools
43
import logging
54
import socket
@@ -10,6 +9,7 @@
109
import arrow
1110
import redis.exceptions
1211
from redis.asyncio.lock import Lock
12+
from servicelib.logging_errors import create_troubleshootting_log_kwargs
1313

1414
from ..background_task import periodic
1515
from ._client import RedisClientSDK
@@ -138,10 +138,21 @@ async def _wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
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:
141+
except redis.exceptions.LockNotOwnedError as exc:
142142
_logger.exception(
143-
"Unexpected error with lock '%s', cannot release it",
144-
redis_lock_key,
143+
**create_troubleshootting_log_kwargs(
144+
f"Unexpected error while releasing lock '{redis_lock_key}'",
145+
error=exc,
146+
error_context={
147+
"redis_lock_key": redis_lock_key,
148+
"lock_value": lock_value,
149+
"client_name": client.client_name,
150+
"hostname": socket.gethostname(),
151+
"coroutine": coro.__name__,
152+
},
153+
tip="This might happen if the lock was lost before releasing it. "
154+
"Look for synchronous code that prevents refreshing the lock or asyncio loop overload.",
155+
)
145156
)
146157

147158
return _wrapper

0 commit comments

Comments
 (0)