Skip to content

Commit 753b751

Browse files
authored
feat(bigquery): widen retry predicate (#6976)
This PR adds 500,504 http response codes for the default retry predicate on unary retries. This doesn't introduce job-level retries (jobs must be recreated wholly, they can't be effectively restarted), so the primary risk of this change is terminal job state propagating into the HTTP response code of one of the polling methods (e.g. job.getQueryResults, jobs.get, etc). In this situation, job execution may appear to hang indefinitely or until context cancellation/expiry. Related: https://togithub.com/googleapis/google-cloud-go/issues/5248
1 parent 0e15a92 commit 753b751

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

β€Žbigquery/bigquery.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,16 @@ func runWithRetryExplicit(ctx context.Context, call func() error, allowedReasons
203203
var (
204204
defaultRetryReasons = []string{"backendError", "rateLimitExceeded"}
205205
jobRetryReasons = []string{"backendError", "rateLimitExceeded", "internalError"}
206+
retry5xxCodes = []int{
207+
http.StatusInternalServerError,
208+
http.StatusBadGateway,
209+
http.StatusServiceUnavailable,
210+
http.StatusGatewayTimeout,
211+
}
206212
)
207213

208-
// This is the correct definition of retryable according to the BigQuery team. It
209-
// also considers 502 ("Bad Gateway") and 503 ("Service Unavailable") errors
210-
// retryable; these are returned by systems between the client and the BigQuery
211-
// service.
214+
// retryableError is the unary retry predicate for this library. In addition to structured error
215+
// reasons, it specifies some HTTP codes (500, 502, 503, 504) and network/transport reasons.
212216
func retryableError(err error, allowedReasons []string) bool {
213217
if err == nil {
214218
return false
@@ -237,8 +241,10 @@ func retryableError(err error, allowedReasons []string) bool {
237241
}
238242
}
239243
}
240-
if e.Code == http.StatusServiceUnavailable || e.Code == http.StatusBadGateway {
241-
return true
244+
for _, code := range retry5xxCodes {
245+
if e.Code == code {
246+
return true
247+
}
242248
}
243249
case *url.Error:
244250
retryable := []string{"connection refused", "connection reset"}

β€Žbigquery/bigquery_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TestRetryableErrors(t *testing.T) {
8686
&googleapi.Error{
8787
Code: http.StatusInternalServerError,
8888
},
89-
false,
89+
true,
9090
},
9191
{
9292
"internal w/backend reason",

0 commit comments

Comments
 (0)