Skip to content

Commit

Permalink
Merge pull request #457 from guggero/client-ping
Browse files Browse the repository at this point in the history
server: specify gRPC keepalive params
  • Loading branch information
positiveblue authored Jun 5, 2023
2 parents cdca09e + 820b4e4 commit e5d6a5f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"strings"
"sync"
"sync/atomic"
"time"

"github.com/btcsuite/btcd/btcec/v2"
proxy "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
Expand All @@ -34,6 +35,7 @@ import (
"github.com/lightningnetwork/lnd/macaroons"
"github.com/lightningnetwork/lnd/signal"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
"google.golang.org/grpc/metadata"
"google.golang.org/protobuf/encoding/protojson"
"gopkg.in/macaroon-bakery.v2/bakery"
Expand Down Expand Up @@ -68,6 +70,12 @@ var (
"signrpc", "walletrpc", "chainrpc", "invoicesrpc",
},
}

// defaultClientPingTime is the default time we'll use for the client
// keepalive ping time. This means the client will ping the server every
// 10 seconds (if there is no other activity) to make sure the TCP
// connection is still alive.
defaultClientPingTime = 10 * time.Second
)

// Server is the main poold trader server.
Expand Down Expand Up @@ -562,6 +570,20 @@ func (s *Server) setupClient() error {
),
)

// For non-regtest networks we also want to turn on gRPC keepalive to
// detect stale connections. We don't do this for regtest because there
// might be older regtest-only servers out there where this would lead
// to disconnects because the server doesn't allow pings that often
// (since this requires a server side change to be deployed as well).
if s.cfg.Network != "regtest" {
s.cfg.AuctioneerDialOpts = append(
s.cfg.AuctioneerDialOpts,
grpc.WithKeepaliveParams(keepalive.ClientParameters{
Time: defaultClientPingTime,
}),
)
}

// Create the funding manager. The RPC server is responsible for
// starting/stopping it though as all that logic is currently there for
// the other managers as well.
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const semanticAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr
const (
appMajor uint = 0
appMinor uint = 6
appPatch uint = 3
appPatch uint = 4

// appPreRelease MUST only contain characters from semanticAlphabet per
// the semantic versioning spec.
Expand Down

0 comments on commit e5d6a5f

Please sign in to comment.