From 8f91c149e2b75b38412b4f22dd0d5974f3442373 Mon Sep 17 00:00:00 2001 From: YaoZengzeng Date: Tue, 18 Oct 2016 13:50:16 +0800 Subject: [PATCH] add timeout for ocic connect to server Signed-off-by: Yao Zengzeng --- cmd/client/main.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/client/main.go b/cmd/client/main.go index e98469c8..8d7f65a8 100644 --- a/cmd/client/main.go +++ b/cmd/client/main.go @@ -13,13 +13,8 @@ import ( pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime" ) -const ( - // TODO: Make configurable - timeout = 10 * time.Second -) - func getClientConnection(context *cli.Context) (*grpc.ClientConn, error) { - conn, err := grpc.Dial(context.GlobalString("connect"), grpc.WithInsecure(), grpc.WithTimeout(timeout), + conn, err := grpc.Dial(context.GlobalString("connect"), grpc.WithInsecure(), grpc.WithTimeout(context.GlobalDuration("timeout")), grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) { return net.DialTimeout("unix", addr, timeout) })) @@ -87,6 +82,11 @@ func main() { Value: "/var/run/ocid.sock", Usage: "Socket to connect to", }, + cli.DurationFlag{ + Name: "timeout", + Value: 10 * time.Second, + Usage: "Timeout of connecting to server", + }, } if err := app.Run(os.Args); err != nil {