Repository navigation
fix(crawl): retry stop on 503 crawl_busy, honoring a capped Retry-After - #32
Merged
Merged
Conversation
A stop that collides with the crawl saving its own progress answers 503 crawl_busy with Retry-After. Nothing was saved and the crawl keeps running, and the stop is safe to repeat, but stop raised at once. stop now retries that answer up to `retries` times, waiting Retry-After seconds between tries, then raises it. Other errors, and other 503s, are raised as before.
gonzalo-zenrows
marked this pull request as ready for review
October 9, 2026 19:51
gonzalo-zenrows
added this pull request to stack #33
October 9, 2026 19:51
…-stop-retry-busy # Conflicts: # tests/test_crawl_client.py
StefanoGuerrini
self-requested a review
October 12, 2026 13:57
StefanoGuerrini
approved these changes
Oct 12, 2026
StefanoGuerrini
force-pushed
the
crawl-stop-retry-busy
branch
from
October 12, 2026 14:09
506edb0 to
f2918fd
Compare
|
Merged into the feature branch with a merge commit. It ships to main with #31. |
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.
Stacked on #31 (
feat/crawl-client-v2): it merges after #31, and the diff shows only this change.Summary
ZenRowsCrawlClient.stopnow retries a503with problem codecrawl_busy, waitingRetry-Afterseconds between tries. The client caps that wait at 30 s, so a large server value cannot hang a stop. Before this change, the client raised the 503 while the crawl kept running.Problem
POST /v1/crawls/{crawl_id}/stopcan collide with the crawl while it saves its own progress. The API retries that collision on the server for under 2 s. If the collision stays, the API answers503with problemcode: crawl_busyandRetry-After: 1. The API saves nothing, the crawl keeps running, and a second stop is safe.stopraised that 503 at once. Stop is a POST without anIdempotency-Key, so the shared transport never retries it. The caller saw an error while the crawl kept running.Change
stopbehavior503with codecrawl_busyretriesmore times, then raises theCrawlAPIError.retriesis the existing client option (default 3);retries=0turns the retry off.Retry-Aftervalue, at most 30 s. A missing, negative, NaN or infinite value gives 1 s.503with another code, any other errorThe docstrings of
retriesandstopmentioncrawl_busy. The crawl errors table inREADME.mdadds a503 crawl_busyrow.Tests
New tests in
tests/test_crawl_client.pyuse respx and record eachtime.sleepcall:503 crawl_busy, then200:stopreturns the stopped crawl after one 1.0 s wait.503 crawl_busyon every call, withretries=2:stopraises it after 3 calls, with waits[1.0, 1.0].503with another code:stopdoes not retry.Retry-Aftervalue:3600waits 30.0 s,-1andnanwait 1.0 s,2waits 2.0 s.How to try it
Squash-merge with the title as the message: the branch commits carry trailer lines that should not land.