This repository was archived by the owner on Mar 6, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 326
fix: updates timeout/retry code to respect hanging server #2408
Merged
chalmerlowe
merged 14 commits into
main
from
fix-468091307-update-timeout-retry-behavior
Jan 29, 2026
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0ca3d87
fix: updates timeout/retry code to respect hanging server
chalmerlowe f58d712
updates REST interactions to handle timeout
chalmerlowe f62c42b
updates time to monotonic
chalmerlowe 291cfe9
Update retry.py
chalmerlowe 6f0bad0
updates conditional statement to idiomatic python
chalmerlowe 2544afb
updates test suite to accommodate new timeout parameter
chalmerlowe 00eb8b5
revises retry deadline to accommodate the timeout.
chalmerlowe e5973a0
adds two tests to ensure proper coverage
chalmerlowe 90ef70f
updates mock
chalmerlowe 8ee106c
updates mock with subscriptable columns
chalmerlowe 60ae827
Updates tests to account for transitive dependency and older version …
chalmerlowe f263a8d
Removes accidentally added file
chalmerlowe 7e9b9f9
Updates tests with success case
chalmerlowe b7ea81a
merges content from temp file to permanent file, deletes temp file
chalmerlowe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,12 +12,15 @@ | |
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import logging | ||
|
|
||
| from google.api_core import exceptions | ||
| from google.api_core import retry | ||
| import google.api_core.future.polling | ||
| from google.auth import exceptions as auth_exceptions # type: ignore | ||
| import requests.exceptions | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| _RETRYABLE_REASONS = frozenset( | ||
| ["rateLimitExceeded", "backendError", "internalError", "badGateway"] | ||
|
|
@@ -61,14 +64,17 @@ | |
| def _should_retry(exc): | ||
| """Predicate for determining when to retry. | ||
|
|
||
| We retry if and only if the 'reason' is 'backendError' | ||
| or 'rateLimitExceeded'. | ||
| We retry if and only if the 'reason' is in _RETRYABLE_REASONS or is | ||
| in _UNSTRUCTURED_RETRYABLE_TYPES. | ||
| """ | ||
| if not hasattr(exc, "errors") or len(exc.errors) == 0: | ||
| # Check for unstructured error returns, e.g. from GFE | ||
| try: | ||
| reason = exc.errors[0]["reason"] | ||
| except (AttributeError, IndexError, TypeError, KeyError): | ||
| # Fallback for when errors attribute is missing, empty, or not a dict | ||
| # or doesn't contain "reason" (e.g. gRPC exceptions). | ||
| _LOGGER.debug("Inspecting unstructured error for retry: %r", exc) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NOTE to reviewer: Why did we use In the Python Because this code is not in a super-tight loop, the difference is negligible, but none-the-less it is good practice. |
||
| return isinstance(exc, _UNSTRUCTURED_RETRYABLE_TYPES) | ||
chalmerlowe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| reason = exc.errors[0]["reason"] | ||
| return reason in _RETRYABLE_REASONS | ||
|
|
||
|
|
||
|
|
||
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE to reviewer:
Why a monotonic clock? A monotonic clock is guaranteed to move forward or stay still, but never go backward, making it ideal for measuring elapsed time and durations, unlike the system's wall clock (time.time()), which can be adjusted manually or by network time protocols (NTP) (i.e. fall back in the fall). Not likely to be a huge issue here, but good practice for this use case.