mirror of
https://github.com/esphome/esphome.git
synced 2026-10-06 19:06:37 +00:00
[core] Retry PlatformIO downloads on transport-layer errors (#16397)
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user