Compare commits

..

1 commit

Author SHA1 Message Date
cbc59f82fb [#301] rpc: Make client stream initialization get cancelled by dial timeout
All checks were successful
DCO / DCO (pull_request) Successful in 1m17s
Tests and linters / Tests (pull_request) Successful in 1m35s
Tests and linters / Lint (pull_request) Successful in 1m52s
* `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-06 10:22:50 +03:00

View file

@ -52,7 +52,6 @@ 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
@ -80,12 +79,14 @@ 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
}