diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-11-07 10:36:48 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-11-07 12:24:43 +0900 |
commit | 2ed0b9659f0e2546ea7b68238a714484c96c134a (patch) | |
tree | fa1a2c428239a028f34945592403b8b50bfe124f | |
parent | e82327118a96629d2bcd95acc3b65282828604e9 (diff) |
gobgp: replace deprecated grpc WithTimeout
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | cmd/gobgp/cmd/common.go | 3 | ||||
-rw-r--r-- | cmd/gobgp/cmd/root.go | 9 |
2 files changed, 9 insertions, 3 deletions
diff --git a/cmd/gobgp/cmd/common.go b/cmd/gobgp/cmd/common.go index 855b4269..93a7fca5 100644 --- a/cmd/gobgp/cmd/common.go +++ b/cmd/gobgp/cmd/common.go @@ -23,7 +23,6 @@ import ( "net" "os" "strconv" - "time" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -183,7 +182,7 @@ func extractReserved(args []string, keys map[string]int) (map[string][]string, e } func newClient(ctx context.Context) (api.GobgpApiClient, error) { - grpcOpts := []grpc.DialOption{grpc.WithTimeout(time.Second), grpc.WithBlock()} + grpcOpts := []grpc.DialOption{grpc.WithBlock()} if globalOpts.TLS { var creds credentials.TransportCredentials if globalOpts.CaFile == "" { diff --git a/cmd/gobgp/cmd/root.go b/cmd/gobgp/cmd/root.go index e59c8324..d8c606e7 100644 --- a/cmd/gobgp/cmd/root.go +++ b/cmd/gobgp/cmd/root.go @@ -20,6 +20,7 @@ import ( "fmt" "net/http" _ "net/http/pprof" + "time" api "github.com/osrg/gobgp/api" "github.com/spf13/cobra" @@ -43,6 +44,7 @@ var ctx context.Context func NewRootCmd() *cobra.Command { cobra.EnablePrefixMatching = true + var cancel context.CancelFunc rootCmd := &cobra.Command{ Use: "gobgp", PersistentPreRun: func(cmd *cobra.Command, args []string) { @@ -56,9 +58,10 @@ func NewRootCmd() *cobra.Command { if !globalOpts.GenCmpl { var err error - ctx = context.Background() + ctx, cancel = context.WithTimeout(context.Background(), time.Second) client, err = newClient(ctx) if err != nil { + cancel() exitWithError(err) } } @@ -71,6 +74,10 @@ func NewRootCmd() *cobra.Command { } }, PersistentPostRun: func(cmd *cobra.Command, args []string) { + // if children declare thier own, cancel is not called. Doesn't matter because the command will exit soon. + if cancel != nil { + cancel() + } }, } |