Skip to content

Commit 21dde48

Browse files
committed
The retryInterceptor should retry requests on any kind of error
1 parent e02fe9e commit 21dde48

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 {
@@ -524,8 +522,8 @@ func setupCrossSporkClient(config config.Config, logger zerolog.Logger) (*reques
524522
grpcOpts.WithResolvers(mr),
525523
grpcOpts.WithDefaultServiceConfig(json),
526524
grpcOpts.WithUnaryInterceptor(retryInterceptor(
527-
DefaultResourceExhaustedMaxRetryDelay,
528-
DefaultResourceExhaustedRetryDelay,
525+
DefaultMaxRetryDelay,
526+
DefaultRetryDelay,
529527
)),
530528
),
531529
)
@@ -535,8 +533,8 @@ func setupCrossSporkClient(config config.Config, logger zerolog.Logger) (*reques
535533
grpc.WithGRPCDialOptions(
536534
grpcOpts.WithDefaultCallOptions(grpcOpts.MaxCallRecvMsgSize(DefaultMaxMessageSize)),
537535
grpcOpts.WithUnaryInterceptor(retryInterceptor(
538-
DefaultResourceExhaustedMaxRetryDelay,
539-
DefaultResourceExhaustedRetryDelay,
536+
DefaultMaxRetryDelay,
537+
DefaultRetryDelay,
540538
)),
541539
),
542540
)
@@ -594,10 +592,6 @@ func retryInterceptor(maxDuration, pauseDuration time.Duration) grpcOpts.UnaryCl
594592
return nil
595593
}
596594

597-
if status.Code(err) != codes.ResourceExhausted {
598-
return err
599-
}
600-
601595
attempts++
602596
duration := time.Since(start)
603597
if duration >= maxDuration {

0 commit comments

Comments
 (0)