Compare commits

..

1 commit

Author SHA1 Message Date
a5a399f748 [#301] rpc: Make client stream initialization get cancelled by dial timeout
All checks were successful
DCO / DCO (pull_request) Successful in 1m22s
Tests and linters / Tests (pull_request) Successful in 1m39s
Tests and linters / Lint (pull_request) Successful in 1m56s
* `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 timer with `dialTimeout` for `NewStream` fixes this problem.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2024-12-05 17:08:36 +03:00

View file

@ -52,6 +52,7 @@ func (c *Client) Init(info common.CallMethodInfo, opts ...CallOption) (MessageRe
}
ctx, cancel := context.WithCancel(prm.ctx)
defer cancel()
// `conn.NewStream` doesn't check if `conn` may turn up invalidated right before this invocation.
// In such cases, the operation can hang indefinitely, with the context timeout being the only
@ -79,14 +80,12 @@ func (c *Client) Init(info common.CallMethodInfo, opts ...CallOption) (MessageRe
select {
case <-newStreamCh:
default:
cancel()
return nil, context.Canceled
}
case <-newStreamCh:
}
if err != nil {
cancel()
return nil, err
}