Skip to content

Commit e3c9fc2

Browse files
committed
Reduce the scope of the lock to the minimal needed size
1 parent ea9607e commit e3c9fc2

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/apify/storage_clients/_apify/_request_queue_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ async def fetch_next_request(self) -> Request | None:
294294
Returns:
295295
The request or `None` if there are no more pending requests.
296296
"""
297-
# Ensure the queue head has requests if available
297+
# Ensure the queue head has requests if available. Fetching the head with lock to prevent race conditions.
298298
async with self._fetch_lock:
299299
await self._ensure_head_is_non_empty()
300300

@@ -304,7 +304,8 @@ async def fetch_next_request(self) -> Request | None:
304304

305305
# Get the next request ID from the queue head
306306
next_request_id = self._queue_head.popleft()
307-
request = await self._get_or_hydrate_request(next_request_id)
307+
308+
request = await self._get_or_hydrate_request(next_request_id)
308309

309310
# Handle potential inconsistency where request might not be in the main table yet
310311
if request is None:

0 commit comments

Comments
 (0)