Skip to content

fix(crawlers)!: Retry the request when a middleware cleanup fails - #2591

Draft
Mantisus wants to merge 5 commits into
apify:v2from
Mantisus:middleware-cleanup-errors
Draft

Mantisus wants to merge 5 commits into
apify:v2from
Mantisus:middleware-cleanup-errors

Conversation

@Mantisus

@Mantisus Mantisus commented Dec 5, 2026

Copy link
Copy Markdown
Collaborator

An error in the cleanup of a context pipeline middleware, the code after its yield, now fails only that request. The crawler retries it and, once no retries are left, passes it to the failed request handler instead of ending the crawl. The results of the attempt are dropped, so the retry runs the request handler again, and the error doesn't mark the session as bad. In the built-in crawlers, this covers a failed response.aclose() and a failed copy of browser cookies into the session, for example after the browser crashed.

The pipeline also runs the remaining cleanups after one fails, and a cleanup error no longer replaces an error or a cancellation that is already propagating. Such a cleanup error, like every cleanup error after the first one, is logged as a warning.

Part of #1739.

✍️ Drafted by Claude Code

@Mantisus Mantisus self-assigned this Dec 5, 2026
@github-actions github-actions Bot added the t-tooling Issues with this label are in the ownership of the tooling team. label Dec 5, 2026

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