Skip to content

Commit

Permalink
Set GRPC keep-alive (#260)
Browse files Browse the repository at this point in the history
Our sync streams are being terminated every 1 minute, possibly by the
load balancer, possibly because the connection is idle. Here we set GRPC
keep-alives to keep the connection active. Let's see if this fixes the
issue.

Also added a log to log what a node is registered as.

More info:
- grpc/grpc-node#1747
- https://grpc.io/docs/guides/keepalive/
- https://github.com/grpc/grpc-go/blob/master/Documentation/keepalive.md

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Enhanced logging for registrant identification to improve visibility
during runtime.
- Updated gRPC client connection settings with keepalive parameters for
better connection management.

- **Bug Fixes**
	- None reported.

- **Documentation**
	- None reported.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
richardhuaaa authored Oct 24, 2024
1 parent 8b39992 commit 05f9191
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/registrant/registrant.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func NewRegistrant(

tokenFactory := authn.NewTokenFactory(privateKey, record.NodeID)

log.Info(
"Registrant identified",
zap.Uint32("nodeId", record.NodeID),
)
return &Registrant{
record: record,
privateKey: privateKey,
Expand Down
7 changes: 7 additions & 0 deletions pkg/registry/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package registry
import (
"crypto/ecdsa"
"fmt"
"time"

"github.com/xmtp/xmtpd/pkg/utils"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
)

type DialOptionFunc func(node Node) []grpc.DialOption
Expand Down Expand Up @@ -49,6 +51,11 @@ func (node *Node) BuildClient(
dialOpts := append([]grpc.DialOption{
grpc.WithTransportCredentials(creds),
grpc.WithDefaultCallOptions(),
grpc.WithKeepaliveParams(keepalive.ClientParameters{
Time: 30 * time.Second,
Timeout: 10 * time.Second,
PermitWithoutStream: true,
}),
}, extraDialOpts...)

conn, err := grpc.NewClient(
Expand Down

0 comments on commit 05f9191

Please sign in to comment.