Skip to content

Commit

Permalink
client: skip if circuit breaker is disabled (#9078)
Browse files Browse the repository at this point in the history
ref #8678

Signed-off-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
rleungx authored Feb 13, 2025
1 parent 30e8ed7 commit e893032
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion client/pkg/utils/grpcutil/grpcutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func UnaryBackofferInterceptor() grpc.UnaryClientInterceptor {
func UnaryCircuitBreakerInterceptor() grpc.UnaryClientInterceptor {
return func(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
cb := circuitbreaker.FromContext(ctx)
if cb == nil {
if cb == nil || !cb.IsEnabled() {
return invoker(ctx, method, req, reply, cc, opts...)
}
err := cb.Execute(func() (circuitbreaker.Overloading, error) {
Expand Down
6 changes: 2 additions & 4 deletions tests/integrations/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2267,8 +2267,7 @@ func TestCircuitBreakerOpenAndChangeSettings(t *testing.T) {
*config = cb.AlwaysClosedSettings
})
_, err = cli.GetRegion(ctx, []byte("a"))
re.Error(err)
re.Contains(err.Error(), "ResourceExhausted")
re.NoError(err)
re.NoError(failpoint.Disable("github.com/tikv/pd/client/pkg/utils/grpcutil/triggerCircuitBreaker"))
}

Expand Down Expand Up @@ -2337,8 +2336,7 @@ func TestCircuitBreakerHalfOpenAndChangeSettings(t *testing.T) {
// It won't be changed to open state.
for range 100 {
_, err := cli.GetRegion(ctx, []byte("a"))
re.Error(err)
re.NotContains(err.Error(), "circuit breaker is open")
re.NoError(err)
}
re.NoError(failpoint.Disable("github.com/tikv/pd/client/pkg/utils/grpcutil/triggerCircuitBreaker"))
}

0 comments on commit e893032

Please sign in to comment.