[#324] rpc: Fix mem leak
All checks were successful
DCO / DCO (pull_request) Successful in 26s
Tests and linters / Tests (pull_request) Successful in 44s
Tests and linters / Lint (pull_request) Successful in 2m4s

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 82e48c8a63
commit 1b8bd20fa0
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) ctx, cancel := context.WithCancel(prm.ctx)
defer cancel()
// `conn.NewStream` doesn't check if `conn` may turn up invalidated right before this invocation. // `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 // 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, // would propagate to all subsequent read/write operations on the opened stream,
// which is not desired for the stream's lifecycle management. // which is not desired for the stream's lifecycle management.
dialTimeoutTimer := time.NewTimer(c.dialTimeout) dialTimeoutTimer := time.NewTimer(c.dialTimeout)
defer dialTimeoutTimer.Stop() defer func() {
dialTimeoutTimer.Stop()
select {
case <-dialTimeoutTimer.C:
default:
}
}()
type newStreamRes struct { type newStreamRes struct {
stream grpc.ClientStream stream grpc.ClientStream