Skip to content

Commit b61d6fb

Browse files
committed
rpc: set params for the longest time a connection can be idle
In this commit, we set a gRPC param that controls how long a connection can be idle for. The goal here is to prune the amount of open TCP connections on an active/popular universe server. According to the docs: > Idleness duration is defined since the most recent time the number of outstanding RPCs became zero or the connection establishment.
1 parent b58c230 commit b61d6fb

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

server.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strings"
88
"sync"
99
"sync/atomic"
10+
"time"
1011

1112
proxy "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
1213
"github.com/lightninglabs/lndclient"
@@ -21,6 +22,7 @@ import (
2122
"github.com/lightningnetwork/lnd/lnrpc"
2223
"github.com/lightningnetwork/lnd/macaroons"
2324
"google.golang.org/grpc"
25+
"google.golang.org/grpc/keepalive"
2426
"gopkg.in/macaroon-bakery.v2/bakery"
2527
)
2628

@@ -269,6 +271,12 @@ func (s *Server) RunUntilShutdown(mainErrChan <-chan error) error {
269271
serverOpts = append(serverOpts, rpcServerOpts...)
270272
serverOpts = append(serverOpts, ServerMaxMsgReceiveSize)
271273

274+
keepAliveParams := keepalive.ServerParameters{
275+
MaxConnectionIdle: time.Minute * 2,
276+
}
277+
278+
serverOpts = append(serverOpts, grpc.KeepaliveParams(keepAliveParams))
279+
272280
grpcServer := grpc.NewServer(serverOpts...)
273281
defer grpcServer.Stop()
274282

universe/syncer.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,6 @@ func (s *SimpleSyncer) SyncUniverse(ctx context.Context, host ServerAddr,
461461
return nil, fmt.Errorf("unable to create remote diff "+
462462
"engine: %w", err)
463463
}
464-
465464
defer diffEngine.Close()
466465

467466
// With the engine created, we can now sync the local Universe with the

0 commit comments

Comments
 (0)