Add retry logic to download_and_extract_meshes#120
Open
gbocchio-bdai wants to merge 2 commits into
Open
Conversation
dta-bdai
requested changes
Apr 27, 2026
| asset_name: str = "meshes.zip", | ||
| tag: str | None = None, | ||
| retries: int = 3, | ||
| timeout: float = 30.0, |
Collaborator
There was a problem hiding this comment.
is it in seconds or minutes? Consider specify the unit in the variable name?
| return response | ||
| except (requests.ConnectionError, requests.Timeout, requests.HTTPError) as exc: | ||
| if attempt >= retries - 1: | ||
| raise |
Collaborator
There was a problem hiding this comment.
consider removing this if.. raise: Other raise statements below won't be reached if we raise here.
Author
There was a problem hiding this comment.
I removed the if ... raise. I added a similar if to prevent sleeping on the last retry if it fails.
dta-bdai
requested changes
May 12, 2026
Collaborator
dta-bdai
left a comment
There was a problem hiding this comment.
Thanks for the update! One more request change to simplify the code. Can you please take a look?
| time.sleep(backoff_time_s) | ||
| if last_exception is not None: | ||
| raise last_exception | ||
| raise RuntimeError("Unexpected retry loop termination in _request_with_retry") |
Collaborator
There was a problem hiding this comment.
this line won't never been reached.
Comment on lines
46
to
58
| last_exception: Exception | None = None | ||
| for attempt in range(retries): | ||
| for attempt in range(retries + 1): | ||
| try: | ||
| response = requests.request(method, url, timeout=timeout, **request_kwargs) | ||
| response = requests.request(method, url, timeout=timeout_s, **request_kwargs) | ||
| response.raise_for_status() | ||
| return response | ||
| except (requests.ConnectionError, requests.Timeout, requests.HTTPError) as exc: | ||
| if attempt >= retries - 1: | ||
| raise | ||
| last_exception = exc | ||
| time.sleep(backoff_time) | ||
| except (requests.ConnectionError, requests.Timeout, requests.HTTPError) as request_exception: | ||
| last_exception = request_exception | ||
| if attempt < retries: | ||
| time.sleep(backoff_time_s) | ||
| if last_exception is not None: | ||
| raise last_exception | ||
| raise RuntimeError("Unexpected retry loop termination in _request_with_retry") |
Collaborator
There was a problem hiding this comment.
Suggested change
| last_exception: Exception | None = None | |
| for attempt in range(retries): | |
| for attempt in range(retries + 1): | |
| try: | |
| response = requests.request(method, url, timeout=timeout, **request_kwargs) | |
| response = requests.request(method, url, timeout=timeout_s, **request_kwargs) | |
| response.raise_for_status() | |
| return response | |
| except (requests.ConnectionError, requests.Timeout, requests.HTTPError) as exc: | |
| if attempt >= retries - 1: | |
| raise | |
| last_exception = exc | |
| time.sleep(backoff_time) | |
| except (requests.ConnectionError, requests.Timeout, requests.HTTPError) as request_exception: | |
| last_exception = request_exception | |
| if attempt < retries: | |
| time.sleep(backoff_time_s) | |
| if last_exception is not None: | |
| raise last_exception | |
| raise RuntimeError("Unexpected retry loop termination in _request_with_retry") | |
| for attempt in range(retries): | |
| try: | |
| response = requests.request(method, url, timeout=timeout, **request_kwargs) | |
| response.raise_for_status() | |
| return response | |
| except (requests.ConnectionError, requests.Timeout, requests.HTTPError) as request_exception: | |
| if attempt < retries: | |
| time.sleep(backoff_time_s) | |
| continue | |
| raise request_exception |
Collaborator
There was a problem hiding this comment.
can you try the suggestion?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds a
_request_with_retryfunction tojudo/utils/assets.pyand uses it to download the meshes; essentially makingdownload_and_extract_meshesmore resilient in CI.It's not infrequent for one given HTTP request to fail in CI due to network instability. Adding a few retries solves most transient failures.