From afdf772fc6a90b3010eee9d70ab65e22e276f53f Mon Sep 17 00:00:00 2001 From: Chris Cotter Date: Wed, 5 Jul 2023 13:28:38 -0400 Subject: [PATCH] fix(storage): update gRPC retry codes (#8202) RESOURCE_EXHAUSTED and INTERNAL should also be retryable for gRPC. See internal b/282880909 --- storage/invoke.go | 11 +++++------ storage/invoke_test.go | 8 ++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/storage/invoke.go b/storage/invoke.go index 6fde482404ef..d8f5a6d4a6f6 100644 --- a/storage/invoke.go +++ b/storage/invoke.go @@ -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 { diff --git a/storage/invoke_test.go b/storage/invoke_test.go index 48f19bc0f33f..58f608cb7cd5 100644 --- a/storage/invoke_test.go +++ b/storage/invoke_test.go @@ -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,