Skip to content

Commit c0457b0

Browse files
authored
Use context.WithTimeout instead of grpc.WithTimeout (GoogleCloudPlatform#610)
* Use context.WithTimeout instead of grpc.WithTimeout WithTimeout returns a DialOption that configures a timeout for dialing a ClientConn initially. This is valid if and only if WithBlock() is present. Deprecated: use DialContext and context.WithTimeout instead. * Use DialContext instead of Dial
1 parent faef8b8 commit c0457b0

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

src/frontend/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,10 @@ func mustMapEnv(target *string, envKey string) {
263263

264264
func mustConnGRPC(ctx context.Context, conn **grpc.ClientConn, addr string) {
265265
var err error
266+
ctx, cancel := context.WithTimeout(ctx, time.Second*3)
267+
defer cancel()
266268
*conn, err = grpc.DialContext(ctx, addr,
267269
grpc.WithInsecure(),
268-
grpc.WithTimeout(time.Second*3),
269270
grpc.WithStatsHandler(&ocgrpc.ClientHandler{}))
270271
if err != nil {
271272
panic(errors.Wrapf(err, "grpc: failed to connect %s", addr))

src/productcatalogservice/server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
func TestServer(t *testing.T) {
3131
ctx := context.Background()
3232
addr := run(port)
33-
conn, err := grpc.Dial(addr,
33+
conn, err := grpc.DialContext(ctx, addr,
3434
grpc.WithInsecure(),
3535
grpc.WithStatsHandler(&ocgrpc.ClientHandler{}))
3636
if err != nil {

0 commit comments

Comments
 (0)