Skip to content

Commit fdd557d

Browse files
committed
added separate list for non-retryable exceptions
1 parent 9b57eb4 commit fdd557d

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

packages/google-cloud-bigquery/google/cloud/bigquery/retry.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,19 @@
3434
exceptions.ServiceUnavailable,
3535
requests.exceptions.ChunkedEncodingError,
3636
requests.exceptions.ConnectionError,
37-
requests.exceptions.SSLError,
3837
requests.exceptions.Timeout,
3938
auth_exceptions.TransportError,
4039
)
4140

4241
_DEFAULT_RETRY_DEADLINE = 10.0 * 60.0 # 10 minutes
4342

43+
# Exceptions that are subclasses of types in _UNSTRUCTURED_RETRYABLE_TYPES
44+
# but should not be retried because they typically indicate persistent
45+
# configuration or security issues.
46+
_UNSTRUCTURED_NON_RETRYABLE_TYPES = (
47+
requests.exceptions.SSLError,
48+
)
49+
4450
# Ambiguous errors (e.g. internalError, backendError, rateLimitExceeded) retry
4551
# until the full `_DEFAULT_RETRY_DEADLINE`. This is because the
4652
# `jobs.getQueryResults` REST API translates a job failure into an HTTP error.
@@ -65,9 +71,13 @@
6571
def _should_retry(exc):
6672
"""Predicate for determining when to retry.
6773
68-
We retry if and only if the 'reason' is in _RETRYABLE_REASONS or is
69-
in _UNSTRUCTURED_RETRYABLE_TYPES.
74+
We retry if the 'reason' is in _RETRYABLE_REASONS or if the exception
75+
is an instance of one of the _UNSTRUCTURED_RETRYABLE_TYPES, unless it
76+
is explicitly excluded by being in _UNSTRUCTURED_NON_RETRYABLE_TYPES.
7077
"""
78+
if isinstance(exc, _UNSTRUCTURED_NON_RETRYABLE_TYPES):
79+
return False
80+
7181
try:
7282
reason = exc.errors[0]["reason"]
7383
except (AttributeError, IndexError, TypeError, KeyError):

packages/google-cloud-bigquery/tests/unit/test_retry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_w_unstructured_requests_connectionerror(self):
5353

5454
def test_w_unstructured_requests_sslerror(self):
5555
exc = requests.exceptions.SSLError()
56-
self.assertTrue(self._call_fut(exc))
56+
self.assertFalse(self._call_fut(exc))
5757

5858
def test_w_unstructured_requests_chunked_encoding_error(self):
5959
exc = requests.exceptions.ChunkedEncodingError()

0 commit comments

Comments
 (0)