Skip to content

Commit 96748f9

Browse files
authored
Cherry-pick #9105 to 1.81.x (#9106)
Addresses: #7023 Original PR: #9105 RELEASE NOTES: * grpc: enhance RPC failure error messages to indicate when retries are exhausted.
1 parent 9183222 commit 96748f9

2 files changed

Lines changed: 8 additions & 17 deletions

File tree

stream.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,6 @@ type ClientStream interface {
148148
RecvMsg(m any) error
149149
}
150150

151-
// ErrRetriesExhausted is returned when an RPC exceeds its configured maximum
152-
// number of retry attempts.
153-
//
154-
// # Experimental
155-
//
156-
// Notice: This type is EXPERIMENTAL and may be changed or removed in a
157-
// later release.
158-
var ErrRetriesExhausted = errors.New("max retry attempts exhausted")
159-
160151
// NewStream creates a new Stream for the client side. This is typically
161152
// called by generated code. ctx is used for the lifetime of the stream.
162153
//
@@ -759,7 +750,7 @@ func (a *csAttempt) shouldRetry(err error) (bool, error) {
759750
return false, err
760751
}
761752
if cs.numRetries+1 >= rp.MaxAttempts {
762-
return false, fmt.Errorf("stopped after %d attempts: %w: %w", cs.numRetries+1, ErrRetriesExhausted, err)
753+
return false, fmt.Errorf("max retries exhausted: failed after %d attempts: %w", cs.numRetries+1, err)
763754
}
764755

765756
var dur time.Duration

test/retry_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package test
2020

2121
import (
2222
"context"
23-
"errors"
2423
"fmt"
2524
"io"
2625
"net"
@@ -576,8 +575,8 @@ func (s) TestMaxCallAttempts(t *testing.T) {
576575
t.Fatalf("client: Recv() = %s, %v; want <nil>, error", got, err)
577576
} else if status.Code(err) != codes.Unavailable {
578577
t.Fatalf("client: Recv() = _, %v; want _, Unavailable", err)
579-
} else if !errors.Is(err, grpc.ErrRetriesExhausted) {
580-
t.Fatalf("want: ErrRetriesExhausted, got: %v", err)
578+
} else if !strings.Contains(err.Error(), "retries exhausted") {
579+
t.Fatalf("want: retries exhausted, got: %v", err)
581580
}
582581

583582
serverMu.Lock()
@@ -910,8 +909,8 @@ func (s) TestNoRetry(t *testing.T) {
910909
if status.Code(err) != codes.Unavailable {
911910
t.Fatalf("client: Recv() = _, %v; want _, Unavailable", err)
912911
}
913-
if errors.Is(err, grpc.ErrRetriesExhausted) {
914-
t.Fatalf("client: Recv() error matches ErrRetriesExhausted, want not match")
912+
if strings.Contains(err.Error(), "retries exhausted") {
913+
t.Fatalf("client: EmptyCall() failed with an unexpected 'retries exhausted' error: %v", err)
915914
}
916915

917916
// Test unary RPC
@@ -922,8 +921,9 @@ func (s) TestNoRetry(t *testing.T) {
922921
if status.Code(err) != codes.Unavailable {
923922
t.Fatalf("client: EmptyCall() = _, %v; want _, Unavailable", err)
924923
}
925-
if errors.Is(err, grpc.ErrRetriesExhausted) {
926-
t.Fatalf("client: EmptyCall() error matches ErrRetriesExhausted, want not match")
924+
925+
if strings.Contains(err.Error(), "retries exhausted") {
926+
t.Fatalf("client: EmptyCall() failed with an unexpected 'retries exhausted' error: %v", err)
927927
}
928928
})
929929
}

0 commit comments

Comments
 (0)