Skip to content

Commit 326f052

Browse files
tswastkiraksi
authored andcommitted
fix: ensure query job retry has longer deadline than API request deadline (googleapis#1734)
In cases where we can't disambiguate API failure from job failure, this ensures we can still retry the job at least once.
1 parent 86a97f7 commit 326f052

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

google/cloud/bigquery/retry.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@
3434
auth_exceptions.TransportError,
3535
)
3636

37-
_DEFAULT_JOB_DEADLINE = 60.0 * 10.0 # seconds
37+
_DEFAULT_RETRY_DEADLINE = 10.0 * 60.0 # 10 minutes
38+
39+
# Allow for a few retries after the API request times out. This relevant for
40+
# rateLimitExceeded errors, which can be raised either by the Google load
41+
# balancer or the BigQuery job server.
42+
_DEFAULT_JOB_DEADLINE = 3.0 * _DEFAULT_RETRY_DEADLINE
3843

3944

4045
def _should_retry(exc):
@@ -51,7 +56,7 @@ def _should_retry(exc):
5156
return reason in _RETRYABLE_REASONS
5257

5358

54-
DEFAULT_RETRY = retry.Retry(predicate=_should_retry, deadline=600.0)
59+
DEFAULT_RETRY = retry.Retry(predicate=_should_retry, deadline=_DEFAULT_RETRY_DEADLINE)
5560
"""The default retry object.
5661
5762
Any method with a ``retry`` parameter will be retried automatically,

tests/unit/test_retry.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def test_DEFAULT_JOB_RETRY_predicate():
125125

126126

127127
def test_DEFAULT_JOB_RETRY_deadline():
128-
from google.cloud.bigquery.retry import DEFAULT_JOB_RETRY
128+
from google.cloud.bigquery.retry import DEFAULT_JOB_RETRY, DEFAULT_RETRY
129129

130-
assert DEFAULT_JOB_RETRY._deadline == 600
130+
# Make sure we can retry the job at least once.
131+
assert DEFAULT_JOB_RETRY._deadline > DEFAULT_RETRY._deadline

0 commit comments

Comments
 (0)