From ae14bdd3a3644f47436b598594f2a676be2a378d Mon Sep 17 00:00:00 2001 From: Ahmad Hafe Date: Sun, 28 Jun 2026 22:57:11 +0300 Subject: [PATCH] Add retry with timeout for virtctl download to handle transient SSL errors Wrap the virtctl binary download in TimeoutSampler to retry on SSLError, ConnectionError, and Timeout for up to 2 minutes (10s between attempts). Add per-request timeout to prevent indefinite hangs on stalled connections. Signed-off-by: Ahmad Hafe Co-authored-by: Cursor --- utilities/infra.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/utilities/infra.py b/utilities/infra.py index 788b345eab..136272b90f 100644 --- a/utilities/infra.py +++ b/utilities/infra.py @@ -690,10 +690,25 @@ def download_and_extract_file_from_cluster(tmpdir, url): LOGGER.info(f"Downloading archive using: url={url}") urllib3.disable_warnings() # TODO: remove this when we fix the SSL warning local_file_name = os.path.join(tmpdir, url.split("/")[-1]) - with requests.get(url, verify=False, stream=True) as created_request: - created_request.raise_for_status() - with open(local_file_name, "wb") as file_downloaded: - file_downloaded.writelines(created_request.iter_content(chunk_size=8192)) + for sample in TimeoutSampler( + wait_timeout=TIMEOUT_2MIN, + sleep=TIMEOUT_10SEC, + func=requests.get, + exceptions_dict={ + requests.exceptions.SSLError: [], + requests.exceptions.ConnectionError: [], + requests.exceptions.Timeout: [], + }, + url=url, + verify=False, + stream=True, + timeout=TIMEOUT_30SEC, + ): + with sample: + sample.raise_for_status() + with open(local_file_name, "wb") as file_downloaded: + file_downloaded.writelines(sample.iter_content(chunk_size=8192)) + break LOGGER.info("Extract the downloaded archive.") if url.endswith(zip_file_extension): archive_file_object = zipfile.ZipFile(file=local_file_name)