forked from TrueCloudLab/frostfs-sdk-go
[#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:
parent
2786fadb25
commit
593dd77d84
3 changed files with 40 additions and 12 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue