Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keep alive to gRPC connection #370

Merged
merged 2 commits into from
Feb 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.
vitarb marked this conversation as resolved.
Show resolved Hide resolved
// 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