Skip to content

Commit

Permalink
fix(storage): update gRPC retry codes (#8202)
Browse files Browse the repository at this point in the history
RESOURCE_EXHAUSTED and INTERNAL should also be retryable for gRPC. See internal b/282880909
  • Loading branch information
tritone authored Jul 5, 2023
1 parent 14b95d3 commit afdf772
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
11 changes: 5 additions & 6 deletions storage/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,11 @@ func ShouldRetry(err error) bool {
return true
}
}
// HTTP 429, 502, 503, and 504 all map to gRPC UNAVAILABLE per
// https://grpc.github.io/grpc/core/md_doc_http-grpc-status-mapping.html.
//
// This is only necessary for the experimental gRPC-based media operations.
if st, ok := status.FromError(err); ok && st.Code() == codes.Unavailable {
return true
// UNAVAILABLE, RESOURCE_EXHAUSTED, and INTERNAL codes are all retryable for gRPC.
if st, ok := status.FromError(err); ok {
if code := st.Code(); code == codes.Unavailable || code == codes.ResourceExhausted || code == codes.Internal {
return true
}
}
// Unwrap is only supported in go1.13.x+
if e, ok := err.(interface{ Unwrap() error }); ok {
Expand Down
8 changes: 8 additions & 0 deletions storage/invoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ func TestInvoke(t *testing.T) {
isIdempotentValue: true,
expectFinalErr: true,
},
{
desc: "retryable gRPC error is retried",
count: 1,
initialErr: status.Error(codes.ResourceExhausted, "rate limit"),
finalErr: nil,
isIdempotentValue: true,
expectFinalErr: true,
},
{
desc: "returns non-retryable error after retryable error",
count: 1,
Expand Down

0 comments on commit afdf772

Please sign in to comment.