Skip to content

Commit 4ecebc4

Browse files
committed
Add timeout option for GRPC connection
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
1 parent 6ba0e0f commit 4ecebc4

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

ctr/container.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
func getClient(ctx *cli.Context) types.APIClient {
2929
// reset the logger for grpc to log to dev/null so that it does not mess with our stdio
3030
grpclog.SetLogger(log.New(ioutil.Discard, "", log.LstdFlags))
31-
dialOpts := []grpc.DialOption{grpc.WithInsecure()}
31+
dialOpts := []grpc.DialOption{grpc.WithInsecure(), grpc.WithTimeout(ctx.GlobalDuration("conn-timeout"))}
3232
dialOpts = append(dialOpts,
3333
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
3434
return net.DialTimeout("unix", addr, timeout)

ctr/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"fmt"
55
"os"
6+
"time"
67

78
"github.com/Sirupsen/logrus"
89
"github.com/codegangsta/cli"
@@ -43,6 +44,11 @@ func main() {
4344
Value: "/run/containerd/containerd.sock",
4445
Usage: "address of GRPC API",
4546
},
47+
cli.DurationFlag{
48+
Name: "conn-timeout",
49+
Value: 1 * time.Second,
50+
Usage: "GRPC connection timeout",
51+
},
4652
}
4753
app.Commands = []cli.Command{
4854
checkpointCommand,

0 commit comments

Comments
 (0)