From 1e0ca25db04896078ee65a424287c350a7fb3371 Mon Sep 17 00:00:00 2001 From: Astone Date: Tue, 3 Dec 2019 15:25:58 +0800 Subject: [PATCH] improve code quality --- grpc.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/grpc.go b/grpc.go index ba7a384..62b8d5d 100644 --- a/grpc.go +++ b/grpc.go @@ -339,7 +339,9 @@ func (g *grpcClient) Call(ctx context.Context, req client.Request, rsp interface d, ok := ctx.Deadline() if !ok { // no deadline so we create a new one - ctx, _ = context.WithTimeout(ctx, callOpts.RequestTimeout) + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(ctx, callOpts.RequestTimeout) + defer cancel() } else { // got a deadline so no need to setup context // but we need to set the timeout we pass along