[#324] rpc: Fix mem leak

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2025-01-29 16:32:27 +03:00
parent 00cebd297f
commit d195cb5104
Signed by: dstepanov-yadro
GPG key ID: 237AF1A763293BC0

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
@ -61,7 +62,13 @@ func (c *Client) Init(info common.CallMethodInfo, opts ...CallOption) (MessageRe
// would propagate to all subsequent read/write operations on the opened stream,
// which is not desired for the stream's lifecycle management.
dialTimeoutTimer := time.NewTimer(c.dialTimeout)
defer dialTimeoutTimer.Stop()
defer func() {
dialTimeoutTimer.Stop()
select {
case <-dialTimeoutTimer.C:
default:
}
}()
type newStreamRes struct {
stream grpc.ClientStream