Skip to content

Commit

Permalink
rpc: set params for the longest time a connection can be idle
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Roasbeef committed Dec 9, 2023
1 parent 9ea91a3 commit ed9b703
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 8 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"sync"
"sync/atomic"
"time"

proxy "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/lightninglabs/lndclient"
Expand All @@ -21,6 +22,7 @@ import (
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/macaroons"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
"gopkg.in/macaroon-bakery.v2/bakery"
)

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

keepAliveParams := keepalive.ServerParameters{
MaxConnectionIdle: time.Minute * 2,
}

serverOpts = append(serverOpts, grpc.KeepaliveParams(keepAliveParams))

grpcServer := grpc.NewServer(serverOpts...)
defer grpcServer.Stop()

Expand Down
1 change: 0 additions & 1 deletion universe/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ func (s *SimpleSyncer) SyncUniverse(ctx context.Context, host ServerAddr,
return nil, fmt.Errorf("unable to create remote diff "+
"engine: %w", err)
}

defer diffEngine.Close()

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

0 comments on commit ed9b703

Please sign in to comment.