Skip to content

Commit

Permalink
Add keep alive to gRPC connection (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitarb committed Feb 25, 2021
1 parent 50a785d commit eccb99a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/grpc_dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/backoff"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/keepalive"
"google.golang.org/grpc/metadata"

"go.temporal.io/sdk/internal/common/metrics"
Expand Down Expand Up @@ -79,11 +80,21 @@ func dial(params dialParameters) (*grpc.ClientConn, error) {
cp.Backoff.BaseDelay = retryPollOperationInitialInterval
cp.Backoff.MaxDelay = retryPollOperationMaxInterval

// gRPC utilizes keep alive mechanism to detect dead connections in case if server didn't close them
// gracefully. Client would ping the server periodically and expect replies withing the specified timeout.
// Learn more by reading https://github.com/grpc/grpc/blob/master/doc/keepalive.md
var kap = keepalive.ClientParameters{
Time: 30 * time.Second,
Timeout: 15 * time.Second,
PermitWithoutStream: true,
}

return grpc.Dial(params.HostPort,
grpcSecurityOptions,
grpc.WithChainUnaryInterceptor(params.RequiredInterceptors...),
grpc.WithDefaultServiceConfig(params.DefaultServiceConfig),
grpc.WithConnectParams(cp),
grpc.WithKeepaliveParams(kap),
)
}

Expand Down

0 comments on commit eccb99a

Please sign in to comment.