Skip to content

Commit

Permalink
grpc-proxy: add client keepalive
Browse files Browse the repository at this point in the history
Longhorn-3967

Signed-off-by: Chin-Ya Huang <chin-ya.huang@suse.com>
  • Loading branch information
c3y1huang authored and innobead committed May 26, 2022
1 parent b0df772 commit db66114
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/client/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/keepalive"

rpc "github.com/longhorn/longhorn-instance-manager/pkg/imrpc"
"github.com/longhorn/longhorn-instance-manager/pkg/meta"
Expand Down Expand Up @@ -60,7 +61,14 @@ type ProxyClient struct {

func NewProxyClient(ctx context.Context, ctxCancel context.CancelFunc, address string, port int) (*ProxyClient, error) {
getServiceCtx := func(serviceUrl string) (ServiceContext, error) {
connection, err := grpc.Dial(serviceUrl, grpc.WithInsecure())
dialOptions := []grpc.DialOption{
grpc.WithInsecure(),
grpc.WithKeepaliveParams(keepalive.ClientParameters{
Time: time.Second * 10,
PermitWithoutStream: true,
}),
}
connection, err := grpc.Dial(serviceUrl, dialOptions...)
if err != nil {
return ServiceContext{}, errors.Wrapf(err, "cannot connect to ProxyService %v", serviceUrl)
}
Expand Down

0 comments on commit db66114

Please sign in to comment.