From 29b963d2fe58e928b74e9fa04cfd400d104195ed Mon Sep 17 00:00:00 2001 From: Jason2866 Date: Mon, 13 Apr 2026 13:20:41 +0200 Subject: [PATCH] Skip FileDownloader monkey-patch when native retry support exists Detect if platformio-core's FileDownloader already has a RETRY class attribute (introduced in the upstream retry enhancement). When present, the native implementation handles retries with urllib3.Retry for initial connections and _stream_with_retry for mid-download failures, making the monkey-patch redundant. This avoids double-retry scenarios (up to 5x5 = 25 attempts) and exception type mismatches (native code raises IOError, not PackageException) when running against an enhanced platformio-core. Amp-Thread-ID: https://ampcode.com/threads/T-019d8365-f1fd-713f-80df-fede9167d179 Co-authored-by: Amp --- platform.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/platform.py b/platform.py index b29f036bc..6b63614e1 100644 --- a/platform.py +++ b/platform.py @@ -146,6 +146,11 @@ def patch_file_downloader(): from platformio.package.download import FileDownloader from platformio.package.exception import PackageException + # Skip if FileDownloader already has native retry support (platformio-core with RETRY) + if hasattr(FileDownloader, "RETRY"): + logger.debug("FileDownloader has native retry support, skipping monkey-patch") + return + if getattr(FileDownloader.__init__, "_patched", False): return