Skip to content

Commit fe5e310

Browse files
Fix grpc client dial context
1 parent 0941b13 commit fe5e310

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

service/client/grpc/grpc.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ func (g *grpcClient) call(ctx context.Context, addr string, req client.Request,
129129
grpcDialOptions = append(grpcDialOptions, opts...)
130130
}
131131

132-
ctx, cancel := context.WithTimeout(context.Background(), opts.DialTimeout)
133-
defer cancel()
132+
dialCtx, timeout := context.WithTimeout(ctx, opts.DialTimeout)
133+
defer timeout()
134134

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

211-
var timeout context.CancelFunc
212-
ctx, timeout = context.WithTimeout(ctx, opts.DialTimeout)
211+
dialCtx, timeout := context.WithTimeout(ctx, opts.DialTimeout)
213212
defer timeout()
214213

215-
cc, err := g.pool.getConn(ctx, addr, grpcDialOptions...)
214+
cc, err := g.pool.getConn(dialCtx, addr, grpcDialOptions...)
216215
if err != nil {
217216
return errors.InternalServerError("go.micro.client", fmt.Sprintf("Error sending request: %v", err))
218217
}

0 commit comments

Comments
 (0)