Merge pull request #166 from mlaventure/add-grpc-timeout

Add grpc timeout
This commit is contained in:
Michael Crosby 2016-03-28 10:23:51 -07:00
commit dec6a0dc4d
3 changed files with 8 additions and 1 deletions

1
.gitignore vendored
View file

@ -4,3 +4,4 @@ bin/
ctr/ctr ctr/ctr
hack/benchmark hack/benchmark
*.exe *.exe
integration-test/test-artifacts

View file

@ -28,7 +28,7 @@ import (
func getClient(ctx *cli.Context) types.APIClient { 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 // 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)) 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, dialOpts = append(dialOpts,
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) { grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("unix", addr, timeout) return net.DialTimeout("unix", addr, timeout)

View file

@ -3,6 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"time"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
@ -43,6 +44,11 @@ func main() {
Value: "/run/containerd/containerd.sock", Value: "/run/containerd/containerd.sock",
Usage: "address of GRPC API", Usage: "address of GRPC API",
}, },
cli.DurationFlag{
Name: "conn-timeout",
Value: 1 * time.Second,
Usage: "GRPC connection timeout",
},
} }
app.Commands = []cli.Command{ app.Commands = []cli.Command{
checkpointCommand, checkpointCommand,