diff --git a/internal/rpc/rpc_client.go b/internal/rpc/rpc_client.go index 72c83a6..375efcd 100644 --- a/internal/rpc/rpc_client.go +++ b/internal/rpc/rpc_client.go @@ -18,6 +18,7 @@ import ( "google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/encoding/gzip" + "google.golang.org/grpc/keepalive" "google.golang.org/grpc/metadata" "net/url" "sync" @@ -240,12 +241,15 @@ func (this *RPCClient) init() error { grpc.MaxCallSendMsgSize(512<<20), grpc.UseCompressor(gzip.Name), ) + var keepaliveParams = grpc.WithKeepaliveParams(keepalive.ClientParameters{ + Time: 30 * time.Second, + }) if u.Scheme == "http" { - conn, err = grpc.Dial(u.Host, grpc.WithTransportCredentials(insecure.NewCredentials()), callOptions) + conn, err = grpc.Dial(u.Host, grpc.WithTransportCredentials(insecure.NewCredentials()), callOptions, keepaliveParams) } else if u.Scheme == "https" { conn, err = grpc.Dial(u.Host, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{ InsecureSkipVerify: true, - })), callOptions) + })), callOptions, keepaliveParams) } else { return errors.New("parse endpoint failed: invalid scheme '" + u.Scheme + "'") }