Skip to content

Commit 55afe33

Browse files
committed
Update grpc timeout and logger
Signed-off-by: Derek McGowan <derek@mcgstyle.net>
1 parent d2fc059 commit 55afe33

File tree

5 files changed

+8
-15
lines changed

5 files changed

+8
-15
lines changed

client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ func New(address string, opts ...ClientOpt) (*Client, error) {
8787
gopts := []grpc.DialOption{
8888
grpc.WithBlock(),
8989
grpc.WithInsecure(),
90-
grpc.WithTimeout(60 * time.Second),
9190
grpc.FailOnNonTempDialError(true),
9291
grpc.WithBackoffMaxDelay(3 * time.Second),
9392
grpc.WithDialer(dialer.Dialer),
@@ -107,7 +106,9 @@ func New(address string, opts ...ClientOpt) (*Client, error) {
107106
)
108107
}
109108
connector := func() (*grpc.ClientConn, error) {
110-
conn, err := grpc.Dial(dialer.DialAddress(address), gopts...)
109+
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
110+
defer cancel()
111+
conn, err := grpc.DialContext(ctx, dialer.DialAddress(address), gopts...)
111112
if err != nil {
112113
return nil, errors.Wrapf(err, "failed to dial %q", address)
113114
}

client_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,11 @@ import (
2121
"context"
2222
"flag"
2323
"fmt"
24-
"io/ioutil"
25-
golog "log"
2624
"os"
2725
"os/exec"
2826
"testing"
2927
"time"
3028

31-
"google.golang.org/grpc/grpclog"
32-
3329
"github.com/containerd/containerd/images"
3430
"github.com/containerd/containerd/log"
3531
"github.com/containerd/containerd/namespaces"
@@ -50,9 +46,6 @@ var (
5046
)
5147

5248
func init() {
53-
// Discard grpc logs so that they don't mess with our stdio
54-
grpclog.SetLogger(golog.New(ioutil.Discard, "", golog.LstdFlags))
55-
5649
flag.StringVar(&address, "address", defaultAddress, "The address to the containerd socket for use in the tests")
5750
flag.BoolVar(&noDaemon, "no-daemon", false, "Do not start a dedicated daemon for the tests")
5851
flag.BoolVar(&noCriu, "no-criu", false, "Do not run the checkpoint tests")

cmd/containerd/command/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
gocontext "context"
2121
"fmt"
2222
"io/ioutil"
23-
golog "log"
2423
"net"
2524
"os"
2625
"os/signal"
@@ -50,7 +49,7 @@ high performance container runtime
5049

5150
func init() {
5251
// Discard grpc logs so that they don't mess with our stdio
53-
grpclog.SetLogger(golog.New(ioutil.Discard, "", golog.LstdFlags))
52+
grpclog.SetLoggerV2(grpclog.NewLoggerV2(ioutil.Discard, ioutil.Discard, ioutil.Discard))
5453

5554
cli.VersionPrinter = func(c *cli.Context) {
5655
fmt.Println(c.App.Name, version.Package, c.App.Version, version.Revision)

cmd/containerd/command/publish.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,13 @@ func connect(address string, d func(string, time.Duration) (net.Conn, error)) (*
9595
gopts := []grpc.DialOption{
9696
grpc.WithBlock(),
9797
grpc.WithInsecure(),
98-
grpc.WithTimeout(60 * time.Second),
9998
grpc.WithDialer(d),
10099
grpc.FailOnNonTempDialError(true),
101100
grpc.WithBackoffMaxDelay(3 * time.Second),
102101
}
103-
conn, err := grpc.Dial(dialer.DialAddress(address), gopts...)
102+
ctx, cancel := gocontext.WithTimeout(gocontext.Background(), 60*time.Second)
103+
defer cancel()
104+
conn, err := grpc.DialContext(ctx, dialer.DialAddress(address), gopts...)
104105
if err != nil {
105106
return nil, errors.Wrapf(err, "failed to dial %q", address)
106107
}

cmd/ctr/app/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package app
1919
import (
2020
"fmt"
2121
"io/ioutil"
22-
"log"
2322

2423
"github.com/containerd/containerd/cmd/ctr/commands/containers"
2524
"github.com/containerd/containerd/cmd/ctr/commands/content"
@@ -44,7 +43,7 @@ var extraCmds = []cli.Command{}
4443

4544
func init() {
4645
// Discard grpc logs so that they don't mess with our stdio
47-
grpclog.SetLogger(log.New(ioutil.Discard, "", log.LstdFlags))
46+
grpclog.SetLoggerV2(grpclog.NewLoggerV2(ioutil.Discard, ioutil.Discard, ioutil.Discard))
4847

4948
cli.VersionPrinter = func(c *cli.Context) {
5049
fmt.Println(c.App.Name, version.Package, c.App.Version)

0 commit comments

Comments
 (0)