[core] Retry PlatformIO downloads on transport-layer errors (#16397)

This commit is contained in:
J. Nick Koston
2026-05-13 10:01:42 -05:00
committed by GitHub
parent 8bce32ec35
commit cb520cda6b
2 changed files with 129 additions and 4 deletions
+8 -4
View File
@@ -51,9 +51,13 @@ def patch_file_downloader() -> None:
"""Retry PlatformIO package downloads with exponential backoff.
PlatformIO's ``FileDownloader`` uses an ``HTTPSession`` without built-in
retry for 502/503 errors. We wrap ``__init__`` to retry on
``PackageException`` and close the session between attempts so a new
TCP connection can route to a different CDN edge node.
retry. We wrap ``__init__`` to retry on transient failures and close the
session between attempts so a new TCP connection can route to a different
CDN edge node. We catch both ``PackageException`` (raised when the server
returns a non-200 status such as 502/503) and ``OSError`` -- which covers
``requests.exceptions.ConnectionError``, ``ReadTimeout``, and
``ChunkedEncodingError`` (all subclasses of ``OSError``) that get raised
when the connection is aborted before a response is parsed.
"""
from platformio.package.download import FileDownloader
from platformio.package.exception import PackageException
@@ -70,7 +74,7 @@ def patch_file_downloader() -> None:
try:
original_init(self, *args, **kwargs)
return
except PackageException as e:
except (PackageException, OSError) as e:
if attempt < max_retries - 1:
delay = 2 ** (attempt + 1)
_LOGGER.warning(