Skip to content

Commit b7aa7bc

Browse files
committed
The retryInterceptor should retry requests on any kind of error
1 parent 9dacab3 commit b7aa7bc

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

bootstrap/bootstrap.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ import (
2121
"github.com/rs/zerolog"
2222
"github.com/sethvargo/go-limiter/memorystore"
2323
grpcOpts "google.golang.org/grpc"
24-
"google.golang.org/grpc/codes"
2524
"google.golang.org/grpc/resolver"
2625
"google.golang.org/grpc/resolver/manual"
27-
"google.golang.org/grpc/status"
2826

2927
"github.com/onflow/flow-evm-gateway/api"
3028
"github.com/onflow/flow-evm-gateway/config"
@@ -43,13 +41,13 @@ const (
4341
// DefaultMaxMessageSize is the default maximum message size for gRPC responses
4442
DefaultMaxMessageSize = 1024 * 1024 * 1024
4543

46-
// DefaultResourceExhaustedRetryDelay is the default delay between retries when the server returns
47-
// a ResourceExhausted error.
48-
DefaultResourceExhaustedRetryDelay = 100 * time.Millisecond
44+
// DefaultRetryDelay is the default delay between retries when a gRPC request
45+
// to one of the Access Nodes has errored out.
46+
DefaultRetryDelay = 100 * time.Millisecond
4947

50-
// DefaultResourceExhaustedMaxRetryDelay is the default max request duration when retrying server
51-
// ResourceExhausted errors.
52-
DefaultResourceExhaustedMaxRetryDelay = 30 * time.Second
48+
// DefaultMaxRetryDelay is the default max request duration when retrying failed
49+
// gRPC requests to one of the Access Nodes.
50+
DefaultMaxRetryDelay = 30 * time.Second
5351
)
5452

5553
type Storages struct {
@@ -513,8 +511,8 @@ func setupCrossSporkClient(config config.Config, logger zerolog.Logger) (*reques
513511
grpcOpts.WithResolvers(mr),
514512
grpcOpts.WithDefaultServiceConfig(json),
515513
grpcOpts.WithUnaryInterceptor(retryInterceptor(
516-
DefaultResourceExhaustedMaxRetryDelay,
517-
DefaultResourceExhaustedRetryDelay,
514+
DefaultMaxRetryDelay,
515+
DefaultRetryDelay,
518516
)),
519517
),
520518
)
@@ -524,8 +522,8 @@ func setupCrossSporkClient(config config.Config, logger zerolog.Logger) (*reques
524522
grpc.WithGRPCDialOptions(
525523
grpcOpts.WithDefaultCallOptions(grpcOpts.MaxCallRecvMsgSize(DefaultMaxMessageSize)),
526524
grpcOpts.WithUnaryInterceptor(retryInterceptor(
527-
DefaultResourceExhaustedMaxRetryDelay,
528-
DefaultResourceExhaustedRetryDelay,
525+
DefaultMaxRetryDelay,
526+
DefaultRetryDelay,
529527
)),
530528
),
531529
)
@@ -583,10 +581,6 @@ func retryInterceptor(maxDuration, pauseDuration time.Duration) grpcOpts.UnaryCl
583581
return nil
584582
}
585583

586-
if status.Code(err) != codes.ResourceExhausted {
587-
return err
588-
}
589-
590584
attempts++
591585
duration := time.Since(start)
592586
if duration >= maxDuration {

0 commit comments

Comments
 (0)