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
|
@ -34,10 +34,15 @@ func (w streamWrapper) WriteMessage(m message.Message) error {
|
|||
})
|
||||
}
|
||||
|
||||
func (w *streamWrapper) Close() error {
|
||||
func (w *streamWrapper) closeSend() error {
|
||||
return w.withTimeout(w.ClientStream.CloseSend)
|
||||
}
|
||||
|
||||
func (w *streamWrapper) Close() error {
|
||||
w.cancel()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *streamWrapper) withTimeout(closure func() error) error {
|
||||
ch := make(chan error, 1)
|
||||
go func() {
|
||||
|
@ -50,6 +55,10 @@ func (w *streamWrapper) withTimeout(closure func() error) error {
|
|||
select {
|
||||
case err := <-ch:
|
||||
tt.Stop()
|
||||
select {
|
||||
case <-tt.C:
|
||||
default:
|
||||
}
|
||||
return err
|
||||
case <-tt.C:
|
||||
w.cancel()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue