Skip to content

Commit

Permalink
Fix keepalive enforcement policy
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Moody <joshua.moody@suse.com>
  • Loading branch information
joshimoo authored and innobead committed May 4, 2022
1 parent 5156f22 commit 15efa9b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion app/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"google.golang.org/grpc"
healthpb "google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/keepalive"
"google.golang.org/grpc/reflection"

"github.com/longhorn/longhorn-instance-manager/pkg/health"
Expand Down Expand Up @@ -111,7 +113,12 @@ func start(c *cli.Context) error {
logrus.Info("creating grpc server with no auth")
}

rpcService, listenAt, err := util.NewServer("tcp://"+listen, tlsConfig)
rpcService, listenAt, err := util.NewServer("tcp://"+listen, tlsConfig,
grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{
MinTime: 10 * time.Second,
PermitWithoutStream: true,
}),
)
if err != nil {
return errors.Wrap(err, "failed to setup grpc server")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/grpcutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func Connect(endpoint string, tlsConfig *tls.Config, dialOptions ...grpc.DialOpt
// when using Unix domain sockets. It ensures that gRPC detects a dead connection
// in a timely manner.
// Code lifted from https://github.com/kubernetes-csi/csi-test/commit/6b8830bf5959a1c51c6e98fe514b22818b51eeeb
dialOptions = append(dialOptions, grpc.WithKeepaliveParams(keepalive.ClientParameters{PermitWithoutStream: true}))
dialOptions = append(dialOptions, grpc.WithKeepaliveParams(keepalive.ClientParameters{Time: 30 * time.Second, PermitWithoutStream: true}))

return grpc.Dial(address, dialOptions...)
}
Expand Down

0 comments on commit 15efa9b

Please sign in to comment.