Skip to content

fix(crawlers): Stop interrupted requests from hanging the crawl - #2570

Open
Mantisus wants to merge 1 commit into
apify:v2from
Mantisus:stranded-request-safety-net
Open

Mantisus wants to merge 1 commit into
apify:v2from
Mantisus:stranded-request-safety-net

Conversation

@Mantisus

@Mantisus Mantisus commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Description

When processing a request ends with an exception that the crawler doesn't handle, such as a repeated cancellation of run() or an error_handler that raises, the crawler now gives the request back to the request manager. The request used to stay in progress, so the next run() on the same request queue never finished. A request that's already marked as handled isn't given back, and a reclaim that fails is logged as a warning.

A CancelledError that the request handler or the navigation raises while nothing cancels the task, such as when it awaits a future that something else cancelled, now fails the attempt like any other error, so the request is retried and then fails. The crawl used to hang. AutoscaledPool fails the run with a RuntimeError when its task function raises such a CancelledError.

Two narrow cases remain. If another worker or another client of a shared queue picks up a request after a retry gave it back, and the original attempt is then cancelled during its cleanup, the request is given back a second time. If marking a request as handled fails or is cancelled midway, the request stays in progress until its lock expires, or until the process ends with the file system storage.

Testing

  • New unit tests for the crawler, the context pipeline and the autoscaled pool.

✍️ Drafted by Claude Code

@Mantisus Mantisus self-assigned this Dec 2, 2026
@github-actions github-actions Bot added the t-tooling Issues with this label are in the ownership of the tooling team. label Dec 2, 2026
@Mantisus
Mantisus requested a review from vdusek December 2, 2026 22:02
@Mantisus
Mantisus force-pushed the stranded-request-safety-net branch from 0f25072 to 80b19f3 Compare December 2, 2026 23:20

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant