Skip to content
Permalink
Browse files
fix: retry auth.TransportError errors (#418)
* fix: retry auth.TransportError's

* unwrap exceptions

* lint

* revert exceptions alias

* scope unwrapping and add unit test

* lint

* fix unit test
  • Loading branch information
frankyn committed Apr 26, 2021
1 parent 2adfb59 commit 23a8db839909a0781343cb18edffaea06a0b7092
Showing with 20 additions and 8 deletions.
  1. +10 −7 google/cloud/storage/retry.py
  2. +10 −1 tests/unit/test_retry.py
@@ -14,18 +14,19 @@

import requests

from google.api_core import exceptions
from google.api_core import exceptions as api_exceptions
from google.api_core import retry
from google.auth import exceptions as auth_exceptions

import json


_RETRYABLE_TYPES = (
exceptions.TooManyRequests, # 429
exceptions.InternalServerError, # 500
exceptions.BadGateway, # 502
exceptions.ServiceUnavailable, # 503
exceptions.GatewayTimeout, # 504
api_exceptions.TooManyRequests, # 429
api_exceptions.InternalServerError, # 500
api_exceptions.BadGateway, # 502
api_exceptions.ServiceUnavailable, # 503
api_exceptions.GatewayTimeout, # 504
requests.ConnectionError,
)

@@ -37,8 +38,10 @@ 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, api_exceptions.GoogleAPICallError):
return exc.code in _ADDITIONAL_RETRYABLE_STATUS_CODES
elif isinstance(exc, auth_exceptions.TransportError):
return _should_retry(exc.args[0])
else:
return False

@@ -25,7 +25,16 @@ def _call_fut(self, exc):

return retry._should_retry(exc)

def test_w_retryable_types(self):
def test_w_retryable_transport_error(self):
from google.cloud.storage import retry
from google.auth.exceptions import TransportError as eTransportError
from requests import ConnectionError as rConnectionError

caught_exc = rConnectionError("Remote end closed connection unexpected")
exc = eTransportError(caught_exc)
self.assertTrue(retry._should_retry(exc))

def test_w_wrapped_type(self):
from google.cloud.storage import retry

for exc_type in retry._RETRYABLE_TYPES:

0 comments on commit 23a8db8

Please sign in to comment.