From d195cb5104019a410bd9329703fa01e758981da1 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Wed, 29 Jan 2025 16:32:27 +0300 Subject: [PATCH] [#324] rpc: Fix mem leak Signed-off-by: Dmitrii Stepanov --- api/rpc/client/init.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/api/rpc/client/init.go b/api/rpc/client/init.go index 95e9301a..4edfd0bc 100644 --- a/api/rpc/client/init.go +++ b/api/rpc/client/init.go @@ -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