From 9b2284c97aa087091543e8c12e236eb75c5b8105 Mon Sep 17 00:00:00 2001 From: Danil Uzlov Date: Mon, 19 Jun 2023 16:00:05 +0700 Subject: [PATCH] add reselectcleanup logic into begin Signed-off-by: Danil Uzlov --- pkg/networkservice/common/begin/server.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/networkservice/common/begin/server.go b/pkg/networkservice/common/begin/server.go index 023d22124..295b71af7 100644 --- a/pkg/networkservice/common/begin/server.go +++ b/pkg/networkservice/common/begin/server.go @@ -64,6 +64,16 @@ func (b *beginServer) Request(ctx context.Context, request *networkservice.Netwo } withEventFactoryCtx := withEventFactory(ctx, eventFactoryServer) + + if request.GetConnection().GetState() == networkservice.State_RESELECT_REQUESTED { + if eventFactoryServer.request != nil && eventFactoryServer.request.Connection != nil { + log.FromContext(ctx).Info("Closing connection due to RESELECT_REQUESTED state") + _, closeErr := next.Server(ctx).Close(ctx, eventFactoryServer.request.Connection) + if closeErr != nil { + log.FromContext(ctx).Errorf("Can't close old connection: %v", closeErr) + } + } + } conn, err = next.Server(withEventFactoryCtx).Request(withEventFactoryCtx, request) if err != nil { if eventFactoryServer.state != established { @@ -72,6 +82,7 @@ func (b *beginServer) Request(ctx context.Context, request *networkservice.Netwo } return } + conn.State = networkservice.State_UP eventFactoryServer.request = request.Clone() eventFactoryServer.request.Connection = conn.Clone() eventFactoryServer.state = established