Skip to content

Commit

Permalink
fix: add client side retry to prevent 'transport is closing' errors (#…
Browse files Browse the repository at this point in the history
…6402)

Signed-off-by: Alexander Matyushentsev <[email protected]>
  • Loading branch information
Alexander Matyushentsev authored and alexmt committed Jun 4, 2021
1 parent 0310d4b commit fab0e82
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/apiclient/apiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"github.com/coreos/go-oidc"
"github.com/dgrijalva/jwt-go/v4"
"github.com/golang/protobuf/ptypes/empty"
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
log "github.com/sirupsen/logrus"
"golang.org/x/oauth2"
"google.golang.org/grpc"
Expand Down Expand Up @@ -466,9 +468,15 @@ func (c *client) newConn() (*grpc.ClientConn, io.Closer, error) {
endpointCredentials := jwtCredentials{
Token: c.AuthToken,
}
retryOpts := []grpc_retry.CallOption{
grpc_retry.WithMax(3),
grpc_retry.WithBackoff(grpc_retry.BackoffLinear(1000 * time.Millisecond)),
}
var dialOpts []grpc.DialOption
dialOpts = append(dialOpts, grpc.WithPerRPCCredentials(endpointCredentials))
dialOpts = append(dialOpts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(MaxGRPCMessageSize), grpc.MaxCallSendMsgSize(MaxGRPCMessageSize)))
dialOpts = append(dialOpts, grpc.WithStreamInterceptor(grpc_retry.StreamClientInterceptor(retryOpts...)))
dialOpts = append(dialOpts, grpc.WithUnaryInterceptor(grpc_middleware.ChainUnaryClient(grpc_retry.UnaryClientInterceptor(retryOpts...))))

ctx := context.Background()

Expand Down

0 comments on commit fab0e82

Please sign in to comment.