Skip to content

Commit 193de10

Browse files
vdusekclaude
andauthored
fix: Guard ReentrantLock against None task context (#841)
Add a runtime guard in `ReentrantLock` to raise `RuntimeError` when `asyncio.current_task()` returns `None`, preventing the lock from being silently bypassed due to `None is None` evaluating to `True`. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5e4f773 commit 193de10

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/apify/_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ def __init__(self) -> None:
141141
async def __call__(self) -> AsyncIterator[None]:
142142
"""Acquire the lock if it's not already owned by the current task, otherwise proceed without acquiring."""
143143
me = asyncio.current_task()
144+
if me is None:
145+
raise RuntimeError('ReentrantLock must be used within an asyncio.Task')
144146
if self._owner is me:
145147
yield
146148
return

0 commit comments

Comments
 (0)