Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: specify gRPC keepalive params #457

Merged
merged 2 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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