@@ -19,6 +19,10 @@ import (
19
19
grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/retry"
20
20
)
21
21
22
+ const (
23
+ timeout = time .Minute
24
+ )
25
+
22
26
// Deprecated: Use NewClient instead.
23
27
func DialContext (_ context.Context , addr string ) (* grpc.ClientConn , error ) {
24
28
return NewClient (addr )
@@ -44,7 +48,11 @@ func NewClient(addr string) (*grpc.ClientConn, error) {
44
48
grpc_retry .StreamClientInterceptor (opts ... ),
45
49
func (ctx context.Context , desc * grpc.StreamDesc , cc * grpc.ClientConn , method string , streamer grpc.Streamer , opts ... grpc.CallOption ) (grpc.ClientStream , error ) {
46
50
start := time .Now ()
47
- cs , err := streamer (prepareClientContext (ctx ), desc , cc , method , opts ... )
51
+
52
+ ctx , cancel := context .WithTimeout (prepareClientContext (ctx ), timeout )
53
+ defer cancel ()
54
+
55
+ cs , err := streamer (ctx , desc , cc , method , opts ... )
48
56
log .Ctx (ctx ).Debug ().Str ("method" , method ).
49
57
Dur ("duration" , time .Since (start )).
50
58
Str ("type" , "stream" ).
@@ -58,7 +66,11 @@ func NewClient(addr string) (*grpc.ClientConn, error) {
58
66
grpc_retry .UnaryClientInterceptor (opts ... ),
59
67
func (ctx context.Context , method string , req , reply interface {}, cc * grpc.ClientConn , invoker grpc.UnaryInvoker , opts ... grpc.CallOption ) error {
60
68
start := time .Now ()
61
- err := invoker (prepareClientContext (ctx ), method , req , reply , cc , opts ... )
69
+
70
+ ctx , cancel := context .WithTimeout (prepareClientContext (ctx ), timeout )
71
+ defer cancel ()
72
+
73
+ err := invoker (ctx , method , req , reply , cc , opts ... )
62
74
log .Ctx (ctx ).Debug ().Str ("method" , method ).
63
75
Dur ("duration" , time .Since (start )).
64
76
Str ("type" , "unary" ).
0 commit comments