retry when transient HTTP errors occur#463
Conversation
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
@coderabbitai analyze if the PR can solve Github transient errors 502 and 503 when trying to download |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 4628 🌐 Web query: 💡 Result: In PlatformIO Core, HTTP 502/503 during package downloads is handled in Where it happens (source)
Related: where PlatformIO does configure retries for 502/503
Sources: Citations:
Analysis: Retry Logic for Transient HTTP 502/503 ErrorsRoot Cause ContextPlatformIO's Interestingly, PlatformIO's What the PR Does1. This wraps
2. Retry loop in Adds retry logic for fetching the Arduino framework metadata JSON with the same 5-attempt exponential backoff, catching Will It Solve Transient 502/503 Errors?
Minor Caveats
Verdict✅ Yes, this PR should effectively solve GitHub transient 502/503 errors for both package downloads and framework metadata fetches. The monkey-patch approach is a pragmatic and well-structured workaround for the gap in PlatformIO's own retry infrastructure specifically affecting |
|
@coderabbitai fetching 404 errors is good. Github answers sometimes with wrong codes. There are no 404 errors since the packages are verified before to be available. |
|
Tip For best results, initiate chat on the files or code changes.
This fully addresses the "minor caveat" I raised in the previous analysis. The PR's retry strategy is sound and well-suited to GitHub's real-world behavior. ✅ ✏️ Learnings added
🧠 Learnings used |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@platform.py`:
- Line 145: The docstring for PlatformIO's FileDownloader in platform.py
incorrectly states retries are limited to 502/503, while the implementation
retries all PackageException HTTP errors; update that docstring to describe the
actual behavior (i.e., retries on any PackageException / all HTTP error status
codes, including 404) and note that this broad retry behavior is intentional for
package downloads so future maintainers don't regress it; reference the
FileDownloader implementation and the retry logic that raises/handles
PackageException when composing the new docstring.
- Around line 621-626: The code calls response.json() to parse packjdata but
doesn't handle JSON decode errors, so add ValueError to the exceptions caught in
the retry block so malformed/non-JSON bodies trigger the same retry logic;
update the except clause that currently catches (requests.RequestException,
KeyError, IndexError) to also include ValueError and keep the existing retry
behavior around packjdata = response.json(), dyn_lib_url and the assignment to
self.packages["framework-arduinoespressif32-libs"]["version"], using the same
attempt/max_retries flow.
- Around line 172-173: The silent catch "except Exception: pass" in platform.py
should be replaced with explicit handling: change it to "except Exception as e:"
and log the exception (e.g., logger.debug or logger.exception with
exc_info=True) including contextual info about the retry/cleanup operation so
diagnostics are preserved; if the cleanup can fail fatally, either re-raise the
exception or narrow the catch to specific expected exception types instead of a
blanket Exception to avoid hiding real errors.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
Updated exception handling in patch_file_downloader to include ValueError. Modified docstring to clarify retry on transient HTTP errors.
Checklist:
Summary by CodeRabbit