fix(avito): gate 403 reconnect-retry on proxy presence only (was dead code in prod) #1765
No reviewers
Labels
No labels
admin
analytics
auth
automation
bug
business
chore
ci
compliance
data
data-moat
docs
duplicate
dx
enhancement
Fable 5 ревью
feedback/max
generative
GG-форсайт
needs-discussion
needs-human
observability
pause-bots
performance
priority/p0
priority/p1
priority/p2
priority/p3
scope/backend
scope/db
scope/devops
scope/frontend
scope/qa
scrapers
security
site-finder
stage/1
stage/2
status/blocked
status/done
status/needs-analysis
status/needs-fix
status/qa
status/ready
status/review
status/wip
tech-debt
tradein
ux
week ревью 1
wontfix
вторичка
ИРД
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: lekss361/gendesign#1765
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "fix/avito-403-reconnect-gate"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem — #1764 was dead code in production (prod run 212 banned again)
PR #1764 added a 403/firewall reconnect-retry in
_fetch_serp_html, gated by:Prod has both
SCRAPER_PROXY_URL(the backconnect proxy — what the curl_cffi session actually egresses through) and a leftoverAVITO_PROXY_ROTATE_URL(a changeip URL for the separate auv/browser proxy). Sonot avito_proxy_rotate_url→ False →backconnect=False→ the reconnect-retry never executed. WithAVITO_PROXY_MAX_ROTATIONS=0the changeip path is a no-op too, so a single SERP 403 still aborted the whole sweep.Run 212 banned on a 403 at
room_1_komnpage 20 with zero reconnect-retries logged — confirming the branch was dead.The two proxies are independent:
_rotate_ip()/avito_proxy_rotate_urlis a changeip API for the auv proxy; the curl_cffi session in__aenter__buildsproxiesfromsettings.scraper_proxy_urlonly. Rebuilding that session (_reset_cffi) yields a fresh backconnect exit IP regardless of any changeip config. (Verified: the backconnect proxy hands a distinct exit IP per new connection — 5 requests → 5 IPs. We don't control which IP; we only control when to grab a new connection.)Fix
One logic line — gate the reconnect-retry on proxy presence only:
Block ordering unchanged: the changeip path (
rot_done < max_rot and _rotate_ip()) is still tried first when a rotate_url +max_rotations>0are configured; reconnect-retry remains the fallback before the finalraise. Under prod'smax_rotations=0, changeip is skipped and the reconnect path now fires.Tests
test_non_backconnect_with_rotate_url_no_reconnect_pathwithtest_reconnect_fires_even_when_rotate_url_set— the exact run-212 prod config (proxy + rotate_url +max_rotations=0): 403→403→200 reconnects (_reset_cffiawaited 2×,_rotate_ipnot awaited).test_changeip_path_tried_first_when_rotations_available(proxy + rotate_url +max_rotations=1→_rotate_ipfirst, no reconnect) to guard changeip precedence.Target file: 5 passed.
tests/scrapers/ -k avito: 57 passed. Ruff clean. (Pre-existingpsycopg2collection errors in unrelated modules are environment issues, not from this change.)Follow-up to #1764; needed to make the reconnect-retry actually run in prod.