fix(scrapy): stop silently dropping in-flight requests and redirects - #1097
Open
vdusek wants to merge 5 commits into
Open
fix(scrapy): stop silently dropping in-flight requests and redirects#1097vdusek wants to merge 5 commits into
vdusek wants to merge 5 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1097 +/- ##
==========================================
+ Coverage 92.31% 92.51% +0.20%
==========================================
Files 51 51
Lines 3317 3382 +65
==========================================
+ Hits 3062 3129 +67
+ Misses 255 253 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Two request-loss bugs in the Scrapy integration, both from
next_request()marking a request handled the moment it is fetched, before Scrapy has downloaded anything.In-flight requests were lost on migration. Everything sitting in the downloader or the parse pipeline was already
handled_at-stamped, so an interrupted run dropped all of it, andreclaim_requestwas never called anywhere in the integration. A request now stays unresolved in the queue until Scrapy is done with it, tracked throughdownloader.activeandscraper.slot.active— a request leaves both only once its download, the middleware chain, the callback and the item pipeline have finished, so the dataset push is covered too. Reconstruction failures are still consumed immediately.Killing a process with three requests in flight: 3 handled / 0 pending before, all three lost; 0 handled / 3 pending after, all fetchable next run. A graceful SIGINT resolves exactly what completed: 6 responses, 6 handled, 5 pending, no duplicates.
Every redirect on a discovered link was dropped.
RedirectMiddlewarederives the new request withrequest.replace(url=...), which inheritsmeta['apify_request_unique_key'], soadd_requestansweredwas_already_present=Trueandenqueue_requestreturnedFalse— a silent drop with no error. Start URLs and retries were masked only by theirdont_filter=True.to_scrapy_requestnow stampsmeta['apify_request_url']alongside the key, and the key is reused only while that URL still matches. A hand-set stamp without a URL is still honored.Reactor stalls.
next_request()did two serial blocking API round trips per request on the reactor thread; now one. Marks go through a fire-and-forgetAsyncThread.submit_coro, drained beforeis_finished()is consulted and before the event loop closes. A hard kill can still lose a mark, leaving that request pending for the next run — at-least-once is the safe direction.✍️ Drafted by Claude Code