Skip to content

Commit f30b0b3

Browse files
committed
Improve error handling on retryInterceptor
1 parent f04957f commit f30b0b3

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"
@@ -587,6 +589,19 @@ func retryInterceptor(maxDuration, pauseDuration time.Duration) grpcOpts.UnaryCl
587589
return nil
588590
}
589591

592+
switch status.Code(err) {
593+
case codes.Canceled, codes.DeadlineExceeded:
594+
// these kind of errors are guaranteed to fail all requests,
595+
// if the source was a local context
596+
return err
597+
case codes.ResourceExhausted, codes.OutOfRange, codes.NotFound:
598+
// when we receive these errors, we pause briefly, so that
599+
// the next request on the same AN, has a higher chance
600+
// of success.
601+
default:
602+
return err
603+
}
604+
590605
attempts++
591606
duration := time.Since(start)
592607
if duration >= maxDuration {

0 commit comments

Comments
 (0)