Skip to content

fix(fetch): ~110s retry budget, honour Retry-After, retry 429/408, report attempts (#1463) - #1597

Merged
zackees merged 2 commits into
mainfrom
fix/1463-download-retry-budget
Sep 30, 2026
Merged

zackees merged 2 commits into
mainfrom
fix/1463-download-retry-budget

Conversation

@zackees

@zackees zackees commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Partially addresses #1463 (does not close it; see the list at the bottom).

In downloader.rs:

  • Longer budget. Same five attempts, but waits are now 5 s, 15 s, 30 s, 60 s (was 1, 2, 4, 8 s): about 110 s instead of 15 s, so a vendor host or CDN edge that is down for a minute or two no longer outlasts every retry (the ClearCore teknic.com failure).
  • Retry-After honoured (delta-seconds form) on retryable statuses: the wait is the larger of our schedule and the server's ask, capped at 120 s.
  • 429 and 408 are retried like a 5xx; every other 4xx still fails fast.
  • The final error says what happened: … (after 5 attempts over 112.3s) / (after 1 attempt over 0.1s), so CI output can tell "retried 5×" from "never retried". (Streaming downloads already reported attempts and byte offset.)

Tests (real local TCP fault-injection server, millisecond timings): 429→408→200 succeeds; Retry-After: 1 delays the retry by ≥1 s; error text carries attempt count and elapsed time for both exhaustion and fail-fast 404; Retry-After parsing; status classification; the policy test pins the new schedule (≥90 s, ≤300 s, one wait per retry). Existing retry/streaming tests unchanged and green: fetch/library/toolchain/build-engine lib suites 480/297/175/155 pass, clippy -D warnings clean.

Trade-off worth a look: a fetch from a genuinely dead host now fails after ~110 s instead of ~15 s.

Not done (still open on the issue): env-configurable attempts/wait (FBUILD_DOWNLOAD_MAX_ATTEMPTS/MAX_WAIT), jitter, mirror/fallback URLs and the primary-down-then-mirror test, a client-side line per retry (retries are still logged only in the daemon), and routing every fetcher (registry/metadata JSON) through this one helper. Resume-on-retry and a content-addressed cache short-circuit already existed.

Summary by CodeRabbit

  • Bug Fixes
    • Package downloads now retry temporary server and rate-limit errors with increasing delays, while respecting supported server-provided retry times.
    • Other client errors fail without repeated retries.
    • If a download still fails, the error now includes the number of attempts and time elapsed.

@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: FastLED/fbuild/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 2eea2828-5fd6-49ef-bdbd-7e8851454a96

📥 Commits

Reviewing files that changed from the base of the PR and between a690e57 and d4aa0f1.

📒 Files selected for processing (2)
  • crates/fbuild-packages-fetch/src/downloader.rs
  • crates/fbuild-packages-fetch/src/downloader_tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The downloader now retries HTTP 5xx, 429, and 408 responses using scheduled backoffs of 5, 15, 30, and 60 seconds. It parses delta-seconds Retry-After values, caps them at 120 seconds, and includes attempt count and elapsed time in final failure errors.

Changes

Package downloader retries

Layer / File(s) Summary
HTTP status and retry-delay handling
crates/fbuild-packages-fetch/src/downloader.rs, crates/fbuild-packages-fetch/src/downloader_tests.rs
HTTP status errors retain an optional parsed Retry-After duration. The downloader retries 5xx, 429, and 408 responses. Tests cover retryable statuses and delta-seconds parsing; HTTP dates are not parsed.
Backoff, retry execution, and failure details
crates/fbuild-packages-fetch/src/downloader.rs, crates/fbuild-packages-fetch/src/downloader_tests.rs
The retry loop uses scheduled backoffs of 5, 15, 30, and 60 seconds. It waits for the larger of the scheduled backoff and a valid server delay capped at 120 seconds. Final errors include attempt count and elapsed time. Tests cover retry timing, successful retries, and failure details.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant get_with_retry
  participant HTTP_endpoint
  participant DownloadAttemptError
  get_with_retry->>HTTP_endpoint: Send package request
  HTTP_endpoint-->>get_with_retry: Return HTTP status and Retry-After header
  get_with_retry->>DownloadAttemptError: Classify status and parse retry delay
  DownloadAttemptError-->>get_with_retry: Return retryability and optional delay
  get_with_retry->>get_with_retry: Select the larger scheduled or capped server delay
  get_with_retry->>HTTP_endpoint: Retry package request
Loading

Merge Risk: ⚪ Minimal · up to d4aa0

The downloader intentionally waits longer for transient failures and reports attempts and elapsed time. No actionable merge-blocking risk remains after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to d4aa0

Server responses can prolong package installation and delay other installations of the same package. Finite retry limits and request timeouts contain this exposure, while staged publication and checksum verification, when configured, remain in place. No new privilege or verification bypass was established.

Retained concerns

  • Low · security · inferred: Remote retryable responses can prolong exclusive package-install ownership. Four Retry-After waits can add 480 seconds of sleeping to a no-progress download, beyond the 110-second scheduled backoff. The installer retains its same-package lock during these waits, potentially delaying dependent installations. Attempt ceilings bound the effect, but the downloader does not enforce an aggregate elapsed-time deadline.
Security review details

Security Blast Radius

  • inferred — The demonstrated exposure is the caller’s download operation and installations contending for the same install path. Exploiting the added delay requires control over responses from an endpoint the caller already contacts. Broader tenant, service, or environment-wide reachability was not established.

Security Findings and Attack Paths

  • inferred — An endpoint returning retryable statuses with a large numeric Retry-After can cause repeated 120-second waits while the package-install lock remains held. This is bounded availability amplification of an existing download path, not an established gain in authority or access to another destination.

Trust Boundaries and Controls

  • observed — Response-controlled delays are capped, apply only on retryable failures, and remain subject to attempt ceilings. Downloader errors stop staged installation before extraction or commit. A configured checksum is still checked before extraction; this control is not unconditional.

Resilience and Maintainability Implications

  • observed — The default HTTP client limits each request to 300 seconds with a 30-second connect timeout. Buffered retrieval permits five attempts; streaming permits five consecutive no-progress attempts and at most 40 total attempts. These controls bound individual requests and retry counts rather than enforcing the headline 110-second schedule as an overall deadline.

Hardening Proposals

  • proposed — If installation responsiveness requires a total duration guarantee, add an explicit operation-wide deadline covering requests and retry sleeps, with defined cancellation cleanup. Keep that guarantee distinct from the scheduled backoff total and the per-response Retry-After cap.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 64.71% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main changes: the retry budget, Retry-After handling, retryable 429/408 responses, and attempt reporting.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant