From 720dc2a1f197568f25914e67aedcef13c1735a90 Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Wed, 4 Dec 2024 18:02:48 +0300 Subject: [PATCH] [#301] rpc: Make client stream initialization get cancelled by dial timeout * `c.conn` may be already invalidated but the rpc client can't detect this. `NewStream` may hang trying to open a stream with invalidated connection. Using context with `dialTimeout` for `NewStream` fixes this problem. Signed-off-by: Airat Arifullin --- api/rpc/client/init.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/rpc/client/init.go b/api/rpc/client/init.go index 706e6a9..9d8dbe1 100644 --- a/api/rpc/client/init.go +++ b/api/rpc/client/init.go @@ -50,7 +50,7 @@ func (c *Client) Init(info common.CallMethodInfo, opts ...CallOption) (MessageRe return nil, err } - ctx, cancel := context.WithCancel(prm.ctx) + ctx, cancel := context.WithTimeout(prm.ctx, c.dialTimeout) stream, err := c.conn.NewStream(ctx, &grpc.StreamDesc{ StreamName: info.Name, ServerStreams: info.ServerStream(),