From 4ecebc4e0f30f428564d4253aac1b6d20d1c1593 Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Mon, 28 Mar 2016 10:09:40 -0700 Subject: [PATCH] Add timeout option for GRPC connection Signed-off-by: Kenfe-Mickael Laventure --- ctr/container.go | 2 +- ctr/main.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ctr/container.go b/ctr/container.go index a23ab57..5182c5c 100644 --- a/ctr/container.go +++ b/ctr/container.go @@ -28,7 +28,7 @@ import ( func getClient(ctx *cli.Context) types.APIClient { // reset the logger for grpc to log to dev/null so that it does not mess with our stdio grpclog.SetLogger(log.New(ioutil.Discard, "", log.LstdFlags)) - dialOpts := []grpc.DialOption{grpc.WithInsecure()} + dialOpts := []grpc.DialOption{grpc.WithInsecure(), grpc.WithTimeout(ctx.GlobalDuration("conn-timeout"))} dialOpts = append(dialOpts, grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) { return net.DialTimeout("unix", addr, timeout) diff --git a/ctr/main.go b/ctr/main.go index 5dcfd24..3fe6396 100644 --- a/ctr/main.go +++ b/ctr/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "os" + "time" "github.com/Sirupsen/logrus" "github.com/codegangsta/cli" @@ -43,6 +44,11 @@ func main() { Value: "/run/containerd/containerd.sock", Usage: "address of GRPC API", }, + cli.DurationFlag{ + Name: "conn-timeout", + Value: 1 * time.Second, + Usage: "GRPC connection timeout", + }, } app.Commands = []cli.Command{ checkpointCommand,