Skip to content

Commit

Permalink
Merge #59309
Browse files Browse the repository at this point in the history
59309: grpcutil: Return true from RequestDidNotStart on open circuit breaker error r=tbg a=mneverov

grpcutil: Return true from RequestDidNotStart on open circuit breaker error

Previously, the gRPC error check returned false on open circuit breaker error
that led to the request retries. Returning true instead should prevent
needless retries.

Fixes: #55869

Release note: None

Co-authored-by: Max Neverov <[email protected]>
  • Loading branch information
craig[bot] and mneverov committed Jan 25, 2021
2 parents 48fbbe7 + 8385a69 commit 8efa63d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/util/grpcutil/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ go_library(
"//pkg/util/netutil",
"//pkg/util/syncutil",
"//pkg/util/timeutil",
"@com_github_cockroachdb_circuitbreaker//:circuitbreaker",
"@com_github_cockroachdb_errors//:errors",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//codes",
Expand All @@ -36,7 +37,9 @@ go_test(
"//pkg/util/leaktest",
"//pkg/util/log/severity",
"//pkg/util/timeutil",
"@com_github_cockroachdb_circuitbreaker//:circuitbreaker",
"@com_github_cockroachdb_errors//:errors",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//health/grpc_health_v1",
Expand Down
4 changes: 3 additions & 1 deletion pkg/util/grpcutil/grpc_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"io"
"strings"

circuit "github.com/cockroachdb/circuitbreaker"
"github.com/cockroachdb/cockroach/pkg/util/netutil"
"github.com/cockroachdb/errors"
"google.golang.org/grpc"
Expand Down Expand Up @@ -111,7 +112,8 @@ func IsAuthenticationError(err error) bool {
// https://github.com/grpc/grpc-go/issues/1443 is resolved.
func RequestDidNotStart(err error) bool {
if errors.HasType(err, connectionNotReadyError{}) ||
errors.HasType(err, (*netutil.InitialHeartbeatFailedError)(nil)) {
errors.HasType(err, (*netutil.InitialHeartbeatFailedError)(nil)) ||
errors.Is(err, circuit.ErrBreakerOpen) {
return true
}
s, ok := status.FromError(errors.Cause(err))
Expand Down
8 changes: 8 additions & 0 deletions pkg/util/grpcutil/grpc_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import (
"strings"
"testing"

circuit "github.com/cockroachdb/circuitbreaker"
"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/testutils/skip"
"github.com/cockroachdb/cockroach/pkg/util/grpcutil"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/errors"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
healthpb "google.golang.org/grpc/health/grpc_health_v1"
)
Expand Down Expand Up @@ -118,3 +120,9 @@ func TestRequestDidNotStart(t *testing.T) {
t.Fatalf("request should not have started, but got %s", err)
}
}

func TestRequestDidNotStart_OpenBreaker(t *testing.T) {
err := errors.Wrapf(circuit.ErrBreakerOpen, "unable to dial n%d", 42)
res := grpcutil.RequestDidNotStart(err)
assert.True(t, res)
}

0 comments on commit 8efa63d

Please sign in to comment.