New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: retry auth.TransportError errors #418
Changes from 1 commit
4f213d9
943898d
180954a
aeee95b
0a1d9e9
020bac3
7bf2c39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,19 +14,21 @@ | |
|
||
import requests | ||
|
||
from google.api_core import exceptions | ||
from google.api_core import exceptions as exceptions_api | ||
from google.api_core import retry | ||
from google.auth import exceptions as exceptions_auth | ||
|
||
import json | ||
|
||
|
||
_RETRYABLE_TYPES = ( | ||
exceptions.TooManyRequests, # 429 | ||
exceptions.InternalServerError, # 500 | ||
exceptions.BadGateway, # 502 | ||
exceptions.ServiceUnavailable, # 503 | ||
exceptions.GatewayTimeout, # 504 | ||
exceptions_api.TooManyRequests, # 429 | ||
exceptions_api.InternalServerError, # 500 | ||
exceptions_api.BadGateway, # 502 | ||
exceptions_api.ServiceUnavailable, # 503 | ||
exceptions_api.GatewayTimeout, # 504 | ||
requests.ConnectionError, | ||
exceptions_auth.TransportError, | ||
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. According to https://github.com/googleapis/google-auth-library-python/blob/36e6f0feb41e901effc854a4f8c907deb9998f21/google/auth/exceptions.py#L22, 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. Doesn't look like there are any subclasses we can use. Maybe we could look at the inner exception, but 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. Yeah, I was wondering whether we should possibly add subclasses in the auth library to allow more differentiation. @frankyn could you speak more to what kind of problems will cause this exception to be raised? 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. When I dug into this, Taking a note from the Go implementation, I'm sending another commit to instead unwrap the inner exception given we already retry on requests.ConnectionError. 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. A bit strange that we are seeing requests.ConnectionError bare, but we're also seeing it wrapped by auth. 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. Yeah I was wondering about this-- would this happen because 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. We still have a feature request to wrap ConnectionError like ResetConnection in api_core, however that doesn't resolve it for the auth library because it does its own wrapping. |
||
) | ||
|
||
# Some retriable errors don't have their own custom exception in api_core. | ||
|
@@ -37,7 +39,7 @@ def _should_retry(exc): | |
"""Predicate for determining when to retry.""" | ||
if isinstance(exc, _RETRYABLE_TYPES): | ||
return True | ||
elif isinstance(exc, exceptions.GoogleAPICallError): | ||
elif isinstance(exc, exceptions_api.GoogleAPICallError): | ||
return exc.code in _ADDITIONAL_RETRYABLE_STATUS_CODES | ||
else: | ||
return False | ||
|
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.
Nit: maybe
api_exceptions
andauth_exceptions
? Or just name the auth one and don't bother aliasing API.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.
We call it
core_exceptions
in BQ