Skip to content

Commit a8a1ce7

Browse files
fix(lock): raise LockNotOwnedError when release a lock from non-owned thread
1 parent dbbe7a7 commit a8a1ce7

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

redis/lock.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,13 @@ def release(self) -> None:
251251
"""
252252
expected_token = self.local.token
253253
if expected_token is None:
254-
raise LockError("Cannot release an unlocked lock", lock_name=self.name)
254+
if self.owned():
255+
raise LockError("Cannot release an unlocked lock", lock_name=self.name)
256+
else:
257+
raise LockNotOwnedError(
258+
"Cannot release a lock that's no longer owned",
259+
lock_name=self.name,
260+
)
255261
self.local.token = None
256262
self.do_release(expected_token)
257263

0 commit comments

Comments
 (0)