[#301] rpc: Make client stream initialization get cancelled by dial timeout
All checks were successful
DCO / DCO (pull_request) Successful in 1m16s
Tests and linters / Tests (pull_request) Successful in 1m36s
Tests and linters / Lint (pull_request) Successful in 1m55s

* `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 <a.arifullin@yadro.com>
This commit is contained in:
Airat Arifullin 2024-12-04 18:02:48 +03:00
parent cb813e27a8
commit 720dc2a1f1

View file

@ -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(),