From ccafb66003ef549b3a4a5e51bee07d1530117b3f Mon Sep 17 00:00:00 2001 From: Artem Glazychev Date: Fri, 26 Nov 2021 17:18:50 +0700 Subject: [PATCH] Change vethpair creation logic Signed-off-by: Artem Glazychev --- .../mechanisms/kernel/kernelvethpair/server.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pkg/networkservice/mechanisms/kernel/kernelvethpair/server.go b/pkg/networkservice/mechanisms/kernel/kernelvethpair/server.go index b5abd7c8..1247497e 100644 --- a/pkg/networkservice/mechanisms/kernel/kernelvethpair/server.go +++ b/pkg/networkservice/mechanisms/kernel/kernelvethpair/server.go @@ -23,6 +23,7 @@ import ( "git.fd.io/govpp.git/api" "github.com/golang/protobuf/ptypes/empty" + "github.com/pkg/errors" "github.com/networkservicemesh/sdk-vpp/pkg/networkservice/mechanisms/kernel/kernelvethpair/mtu" @@ -49,18 +50,20 @@ func NewServer(vppConn api.Connection) networkservice.NetworkServiceServer { } func (k *kernelVethPairServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) { - if err := create(ctx, request.GetConnection(), false); err != nil { - return nil, err - } - postponeCtxFunc := postpone.ContextWithValues(ctx) conn, err := next.Server(ctx).Request(ctx, request) if err != nil { - delCtx, cancelDel := postponeCtxFunc() - defer cancelDel() + return nil, err + } + + if err := create(ctx, request.GetConnection(), false); err != nil { + closeCtx, cancelClose := postponeCtxFunc() + defer cancelClose() - _ = del(delCtx, request.GetConnection(), metadata.IsClient(k)) + if _, closeErr := k.Close(closeCtx, conn); closeErr != nil { + err = errors.Wrapf(err, "connection closed with error: %s", closeErr.Error()) + } return nil, err }