fix(throttling-manager): Open the per-domain sub-queues on first use instead of on insert - #2177
Open
Mantisus wants to merge 5 commits into
Open
fix(throttling-manager): Open the per-domain sub-queues on first use instead of on insert#2177Mantisus wants to merge 5 commits into
Mantisus wants to merge 5 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes throttled request persistence across restarts by lazily opening all configured per-domain queues on first storage operation.
Changes:
- Adds synchronized sub-manager initialization across read/write paths.
- Tracks requests fetched from the inner queue for correct completion routing.
- Adds restart, purge, drop, routing, and concurrency tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/crawlee/request_loaders/_throttling_request_manager.py |
Reopens configured sub-queues and tracks request ownership. |
tests/unit/test_throttling_request_manager.py |
Tests persistence and updated lifecycle behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+437
to
+439
| if request.unique_key in self._in_flight_from_inner: | ||
| self._in_flight_from_inner.discard(request.unique_key) | ||
| return self._inner |
| async with self._sub_managers_lock: | ||
| if self._sub_managers_ready: | ||
| return | ||
| await asyncio.gather(*(self._open_sub_manager(domain) for domain in self._domain_states)) |
Comment on lines
+49
to
+50
| The class is generic over the wrapped manager type. On the first call to any of its methods, the | ||
| `request_manager_opener` callback opens one sub-manager per configured domain, so every sub-manager shares the same |
| self._sub_managers: dict[str, TRequestManager] = {} | ||
| self._sub_managers_ready = False | ||
| self._sub_managers_lock = asyncio.Lock() | ||
| self._in_flight_from_inner: set[str] = set() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
throttled-<domain>queue were invisible: the crawl reported itself finished, andpurge()anddrop()could not clear them either. Resuming those requests needspurge_on_start=False; with the default the queues are now purged at start instead of being left orphaned on disk.Issues
ThrottlingRequestManagernever reopens its sub-queues, so a restart strands throttled requests #2142