From c113a79c707faa8d8fc2cc69b0b6d9198b758fc6 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sun, 22 Nov 2026 01:06:40 +0100 Subject: [PATCH] fix: retry bios files by the shared rule --- installer/download.py | 12 ++++++++---- tests/test_install.py | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/installer/download.py b/installer/download.py index b0080aece..085d33227 100644 --- a/installer/download.py +++ b/installer/download.py @@ -36,7 +36,7 @@ from installer.host_fs import ( ) from installer.invocation import offline_requested from installer.local_check import _digest_file, _digest_handle, expected_hashes, unreachable_words -from installer.network import _retry_delay, _server_delay, network_words +from installer.network import _retry_after_failure, _server_delay, network_words from installer.offline import LOCAL, offline_words from installer.outcome import HttpReason, NetworkReason, OfflineReason, _transfer_failure from installer.pack_source import NOT_IN_PACK, _extract_from_pack @@ -185,6 +185,7 @@ def _fetch_file(job: _FileFetch) -> tuple[str, bool, str]: f = job.f reason: str = "download failed" refused = False + delay: float | None for attempt in range(1, MAX_RETRIES + 1): job.begin() try: @@ -217,7 +218,10 @@ def _fetch_file(job: _FileFetch) -> tuple[str, bool, str]: except urllib.error.HTTPError as exc: reason = _http_attempt_failure(job, exc, attempt) - delay = _server_delay(exc, attempt) + # A 416 refused the partial copy, dropped above: the next attempt + # asks for the whole file. + delay = (_server_delay(exc, attempt) if exc.code == 416 and attempt < MAX_RETRIES + else _retry_after_failure(exc, attempt, MAX_RETRIES)) # http.client raises IncompleteRead (an HTTPException, not an # OSError) when a chunked transfer is cut, as a proxy re-encoding @@ -228,14 +232,14 @@ def _fetch_file(job: _FileFetch) -> tuple[str, bool, str]: print(f" Attempt {attempt} failed: {exc}", file=sys.stderr) if not refused: job.drop_private() - delay = _retry_delay(attempt, None) + delay = _retry_after_failure(exc, attempt, MAX_RETRIES) finally: if job.partial is not None: job.partial.close() job.take_back() - if refused or reason == DRIVE_FULL: + if refused or reason == DRIVE_FULL or delay is None: return f["dest"], False, reason if attempt < MAX_RETRIES and delay and _stop.wait(delay): return f["dest"], False, "stopped" diff --git a/tests/test_install.py b/tests/test_install.py index e2e7148d9..64cc0fa16 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -6418,6 +6418,27 @@ class ANetworkFailureNamesTheNetwork(unittest.TestCase): with self.subTest(error=error): self.assertNotIsInstance(self._fail(error), install.NetworkReason) + def test_a_bios_file_follows_the_shared_retry_rule(self): + """A 404 on a BIOS file was asked three times, the file list once.""" + cases = ((urllib.error.HTTPError("u", 404, "Not Found", None, None), 1), + (urllib.error.HTTPError("u", 503, "Service Unavailable", None, None), + install.MAX_RETRIES)) + for error, expected in cases: + calls: list = [] + + def urlopen(*_args, _error=error, _calls=calls, **_kwargs): + _calls.append(1) + raise _error + + entry = {"dest": "a.bin", "repo_path": "bios/a.bin", "size": 10, + "sha256": "0" * 64} + with self.subTest(code=error.code), \ + unittest.mock.patch.object(install.urllib.request, "urlopen", urlopen), \ + unittest.mock.patch.object(install, "_retry_delay", return_value=0): + _dest, ok, _reason = install._download_one(entry, scratch_dir(self)) + self.assertFalse(ok) + self.assertEqual(len(calls), expected) + def test_the_summary_points_at_the_connection(self): failures = [("a.bin", install.NetworkReason("timed out")), ("b.bin", install.NetworkReason("Connection reset by peer"))]