diff --git a/cln_interceptor.go b/cln_interceptor.go index 194075c..c3a3cc0 100644 --- a/cln_interceptor.go +++ b/cln_interceptor.go @@ -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() diff --git a/cln_plugin/server.go b/cln_plugin/server.go index 58cba3f..e11a240 100644 --- a/cln_plugin/server.go +++ b/cln_plugin/server.go @@ -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)