Skip to content

Commit

Permalink
Fix grpc client dial context
Browse files Browse the repository at this point in the history
  • Loading branch information
LatitudeMaster committed Aug 24, 2023
1 parent 0941b13 commit fe5e310
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions service/client/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ func (g *grpcClient) call(ctx context.Context, addr string, req client.Request,
grpcDialOptions = append(grpcDialOptions, opts...)
}

ctx, cancel := context.WithTimeout(context.Background(), opts.DialTimeout)
defer cancel()
dialCtx, timeout := context.WithTimeout(ctx, opts.DialTimeout)
defer timeout()

cc, err := g.pool.getConn(ctx, addr, grpcDialOptions...)
cc, err := g.pool.getConn(dialCtx, addr, grpcDialOptions...)
if err != nil {
return errors.InternalServerError("go.micro.client", fmt.Sprintf("Error sending request: %v", err))
}
Expand Down Expand Up @@ -208,11 +208,10 @@ func (g *grpcClient) stream(ctx context.Context, addr string, req client.Request
grpcDialOptions = append(grpcDialOptions, opts...)
}

var timeout context.CancelFunc
ctx, timeout = context.WithTimeout(ctx, opts.DialTimeout)
dialCtx, timeout := context.WithTimeout(ctx, opts.DialTimeout)
defer timeout()

cc, err := g.pool.getConn(ctx, addr, grpcDialOptions...)
cc, err := g.pool.getConn(dialCtx, addr, grpcDialOptions...)
if err != nil {
return errors.InternalServerError("go.micro.client", fmt.Sprintf("Error sending request: %v", err))
}
Expand Down

0 comments on commit fe5e310

Please sign in to comment.