Skip to content

Commit

Permalink
fix potential leaks of loopback chain element (#556)
Browse files Browse the repository at this point in the history
Signed-off-by: denis-tingaikin <denis.tingajkin@xored.com>
  • Loading branch information
denis-tingaikin authored Apr 12, 2022
1 parent 19f2f16 commit 8ecddc7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/networkservice/loopback/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (l *loopbackClient) Request(ctx context.Context, request *networkservice.Ne
if err := createLoopback(ctx, l.vppConn, networkService, l.loopbacks, metadata.IsClient(l)); err != nil {
return nil, err
}
postponeCtxFunc := postpone.Context(ctx)
postponeCtxFunc := postpone.ContextWithValues(ctx)
conn, err := next.Client(ctx).Request(ctx, request, opts...)
if err != nil {
closeCtx, cancelClose := postponeCtxFunc()
Expand Down
7 changes: 6 additions & 1 deletion pkg/networkservice/loopback/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/next"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata"
"github.com/networkservicemesh/sdk/pkg/tools/postpone"
)

type loopbackServer struct {
Expand Down Expand Up @@ -53,9 +54,13 @@ func (l *loopbackServer) Request(ctx context.Context, request *networkservice.Ne
if err := createLoopback(ctx, l.vppConn, networkService, l.loopbacks, metadata.IsClient(l)); err != nil {
return nil, err
}
postponeCtxFunc := postpone.ContextWithValues(ctx)

conn, err := next.Server(ctx).Request(ctx, request)
if err != nil {
del(ctx, l.vppConn, networkService, l.loopbacks, metadata.IsClient(l))
closeCtx, cancelClose := postponeCtxFunc()
defer cancelClose()
del(closeCtx, l.vppConn, networkService, l.loopbacks, metadata.IsClient(l))
}
return conn, err
}
Expand Down

0 comments on commit 8ecddc7

Please sign in to comment.