Skip to content

Commit

Permalink
fix memory leak
Browse files Browse the repository at this point in the history
Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com>
  • Loading branch information
NikitaSkrynnik committed Oct 14, 2024
1 parent dfc3300 commit bb11536
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/networkservice/nsmonitor/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,22 @@ func (r *netNSMonitorClient) Request(ctx context.Context, request *networkservic
r.monitor = r.supplyMonitor(r.chainCtx)
})

cancelCtx, cancel := context.WithCancel(r.chainCtx)
if _, ok := metadata.Map(ctx, metadata.IsClient(r)).LoadOrStore(key{}, cancel); !ok {
if _, ok := metadata.Map(ctx, metadata.IsClient(r)).Load(key{}); !ok {
cancelCtx, cancel := context.WithCancel(r.chainCtx)
metadata.Map(ctx, metadata.IsClient(r)).Store(key{}, cancel)
if inodeURL, ok := conn.GetMechanism().GetParameters()[common.InodeURL]; ok {
deleteCh := r.monitor.Watch(cancelCtx, inodeURL)
factory := begin.FromContext(ctx)
go func() {
defer cancel()
select {
case <-r.chainCtx.Done():
return
case <-cancelCtx.Done():
return
case _, ok := <-deleteCh:
if ok && cancelCtx.Err() == nil {
factory.Close(begin.CancelContext(cancelCtx))
<-factory.Close(begin.CancelContext(cancelCtx))
}
return
}
Expand Down

0 comments on commit bb11536

Please sign in to comment.