From 5e100d9bf9b5ea2ab02fd9c03a6d256144e86bf0 Mon Sep 17 00:00:00 2001 From: Blagovest Petrov Date: Wed, 4 Nov 2026 00:23:53 +0200 Subject: [PATCH] fix(agent): send HTTP/2 keepalive pings on the policy connection After a suspend and resume the node's TCP socket to the policy port can stay established while the server has already dropped the connection (its TCP user timeout fires as soon as a push goes unacknowledged for 20 seconds). The agent then sits in Recv on a stream that no longer exists and never sees new bindings until it is restarted. Enable client keepalive: a ping every 60 seconds with a 20 second timeout closes such a connection and the existing reconnect loop takes over. The server's enforcement policy permits pings every 10 seconds. --- agent/internal/policyclient/client.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/agent/internal/policyclient/client.go b/agent/internal/policyclient/client.go index 02fdadfa..574b3473 100644 --- a/agent/internal/policyclient/client.go +++ b/agent/internal/policyclient/client.go @@ -18,6 +18,7 @@ import ( pb "github.com/VuteTech/Bor/server/pkg/grpc/policy" "google.golang.org/grpc" "google.golang.org/grpc/credentials" + "google.golang.org/grpc/keepalive" "google.golang.org/protobuf/types/known/timestamppb" ) @@ -77,6 +78,16 @@ func New(serverAddr, clientID, caCertPath, clientCertPath, clientKeyPath string, conn, err := grpc.NewClient(serverAddr, grpc.WithTransportCredentials(credentials.NewTLS(tlsCfg)), + // HTTP/2 pings so a dead connection is noticed within about a + // minute. After a suspend, a NAT reset or a server restart the TCP + // socket can stay established on the node while the server has + // dropped it; without pings the policy stream would wait forever + // and never see new bindings. The server permits pings every 10 s. + grpc.WithKeepaliveParams(keepalive.ClientParameters{ + Time: 60 * time.Second, + Timeout: 20 * time.Second, + PermitWithoutStream: true, + }), ) if err != nil { return nil, fmt.Errorf("failed to connect to gRPC server %s: %w", serverAddr, err)