[#327] rpc: Fix mem leak

gRPC stream must be closed by `cancel` to prevent memleak.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2025-01-30 10:49:34 +03:00
parent 2786fadb25
commit 593dd77d84
Signed by: dstepanov-yadro
GPG key ID: 237AF1A763293BC0
3 changed files with 40 additions and 12 deletions

View file

@ -41,6 +41,10 @@ type MessageReadWriter interface {
// Init initiates a messaging session and returns the interface for message transmitting.
func (c *Client) Init(info common.CallMethodInfo, opts ...CallOption) (MessageReadWriter, error) {
return c.initInternal(info, opts...)
}
func (c *Client) initInternal(info common.CallMethodInfo, opts ...CallOption) (*streamWrapper, error) {
prm := defaultCallParameters()
for _, opt := range opts {
@ -52,7 +56,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