add keepalive settings for cln client/server

This commit is contained in:
Jesse de Wit
2023-01-06 12:25:29 +01:00
parent 9df0322db4
commit 2d675fe0da
2 changed files with 20 additions and 2 deletions

View File

@@ -19,6 +19,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/keepalive"
"google.golang.org/grpc/status"
)
@@ -45,7 +46,15 @@ func NewClnHtlcInterceptor() *ClnHtlcInterceptor {
func (i *ClnHtlcInterceptor) Start() error {
ctx, cancel := context.WithCancel(context.Background())
log.Printf("Dialing cln plugin on '%s'", i.pluginAddress)
conn, err := grpc.DialContext(ctx, i.pluginAddress, grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.DialContext(
ctx,
i.pluginAddress,
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithKeepaliveParams(keepalive.ClientParameters{
Time: time.Duration(10) * time.Second,
Timeout: time.Duration(10) * time.Second,
}),
)
if err != nil {
log.Printf("grpc.Dial error: %v", err)
cancel()

View File

@@ -9,6 +9,7 @@ import (
"github.com/breez/lspd/cln_plugin/proto"
grpc "google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
)
// Internal htlc_accepted message meant for the sendQueue.
@@ -76,7 +77,15 @@ func (s *server) Start() error {
s.done = make(chan struct{})
s.newSubscriber = make(chan struct{})
s.grpcServer = grpc.NewServer()
s.grpcServer = grpc.NewServer(
grpc.KeepaliveParams(keepalive.ServerParameters{
Time: time.Duration(1) * time.Second,
Timeout: time.Duration(10) * time.Second,
}),
grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{
MinTime: time.Duration(1) * time.Second,
}),
)
s.mtx.Unlock()
proto.RegisterClnPluginServer(s.grpcServer, s)