Skip to content

Commit 9e20910

Browse files
committed
Improve error handling on retryInterceptor
1 parent 0dd4f58 commit 9e20910

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

bootstrap/bootstrap.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ 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"
2425
"google.golang.org/grpc/resolver"
2526
"google.golang.org/grpc/resolver/manual"
27+
"google.golang.org/grpc/status"
2628

2729
"github.com/onflow/flow-evm-gateway/api"
2830
"github.com/onflow/flow-evm-gateway/config"
@@ -579,6 +581,19 @@ func retryInterceptor(maxDuration, pauseDuration time.Duration) grpcOpts.UnaryCl
579581
return nil
580582
}
581583

584+
switch status.Code(err) {
585+
case codes.Canceled, codes.DeadlineExceeded:
586+
// these kind of errors are guaranteed to fail all requests,
587+
// if the source was a local context
588+
return err
589+
case codes.ResourceExhausted, codes.OutOfRange, codes.NotFound:
590+
// when we receive these errors, we pause briefly, so that
591+
// the next request on the same AN, has a higher chance
592+
// of success.
593+
default:
594+
return err
595+
}
596+
582597
attempts++
583598
duration := time.Since(start)
584599
if duration >= maxDuration {

0 commit comments

Comments
 (0)