Skip to content

Commit 67c031e

Browse files
committed
add client keep alive params
1 parent 8292af6 commit 67c031e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

go-routesapi/cmd/sdroutes/main.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/signadot/routesapi/go-routesapi"
1111
"google.golang.org/grpc"
1212
"google.golang.org/grpc/credentials/insecure"
13+
"google.golang.org/grpc/keepalive"
1314
"google.golang.org/protobuf/encoding/protojson"
1415
)
1516

@@ -40,7 +41,12 @@ func main() {
4041
flag.StringVar(&sandboxName, "sandbox-name", "", "routes routing to sandbox with given name")
4142
flag.BoolVar(&watch, "watch", false, "whether to watch")
4243
flag.Parse()
43-
conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
44+
conn, err := grpc.Dial(addr,
45+
grpc.WithTransportCredentials(insecure.NewCredentials()),
46+
grpc.WithKeepaliveParams(keepalive.ClientParameters{
47+
Time: 5 * time.Second,
48+
Timeout: 15 * time.Second,
49+
}))
4450
if err != nil {
4551
log.Fatal(err)
4652
}

go-routesapi/watched/watched.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package watched
33
import (
44
"context"
55
"sync"
6+
"time"
67

78
"github.com/signadot/routesapi/go-routesapi"
89
"github.com/signadot/routesapi/go-routesapi/internal/indices"
910
"github.com/signadot/routesapi/go-routesapi/internal/queue"
1011
"google.golang.org/grpc"
1112
"google.golang.org/grpc/credentials/insecure"
13+
"google.golang.org/grpc/keepalive"
1214
"google.golang.org/protobuf/proto"
1315
)
1416

@@ -43,7 +45,11 @@ type watched struct {
4345
// NewWatched creates a Watched. The set of the workload rules returned from
4446
// the returned Watched corresponds to those specified in q.
4547
func NewWatched(ctx context.Context, cfg *Config, q *routesapi.WorkloadRoutingRulesRequest) (Watched, error) {
46-
conn, err := grpc.Dial(cfg.Addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
48+
conn, err := grpc.Dial(cfg.Addr, grpc.WithTransportCredentials(insecure.NewCredentials()),
49+
grpc.WithKeepaliveParams(keepalive.ClientParameters{
50+
Time: 5 * time.Second,
51+
Timeout: 15 * time.Second,
52+
}))
4753
if err != nil {
4854
return nil, err
4955
}

0 commit comments

Comments
 (0)