Skip to content

Commit

Permalink
begin: use the eventFactory context to close eventFactory connection (#…
Browse files Browse the repository at this point in the history
…1487)

* begin: use the eventFactory context to close eventFactory connection

Signed-off-by: Artem Glazychev <artem.glazychev@xored.com>

* skip Test_DiscoverForwarder_Should_KeepSelectedForwarderWhileConnectionIsFine

Signed-off-by: Artem Glazychev <artem.glazychev@xored.com>

---------

Signed-off-by: Artem Glazychev <artem.glazychev@xored.com>
  • Loading branch information
glazychev-art authored Jul 10, 2023
1 parent 7ec603e commit 01bb35f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pkg/networkservice/chains/nsmgr/select_forwarder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ func Test_DiscoverForwarder_ChangeRemoteForwarderOnDeath(t *testing.T) {
}

func Test_DiscoverForwarder_Should_KeepSelectedForwarderWhileConnectionIsFine(t *testing.T) {
t.Skip("this test is unstable")

t.Cleanup(func() { goleak.VerifyNone(t) })
ctx, cancel := context.WithTimeout(context.Background(), timeout)

Expand Down
9 changes: 6 additions & 3 deletions pkg/networkservice/common/begin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,21 @@ func (b *beginServer) Request(ctx context.Context, request *networkservice.Netwo
return
}

withEventFactoryCtx := withEventFactory(ctx, eventFactoryServer)

if eventFactoryServer.state == established &&
request.GetConnection().GetState() == networkservice.State_RESELECT_REQUESTED &&
eventFactoryServer.request != nil && eventFactoryServer.request.Connection != nil {
log.FromContext(ctx).Info("Closing connection due to RESELECT_REQUESTED state")
_, closeErr := next.Server(withEventFactoryCtx).Close(withEventFactoryCtx, eventFactoryServer.request.Connection)

eventFactoryCtx, eventFactoryCtxCancel := eventFactoryServer.ctxFunc()
_, closeErr := next.Server(eventFactoryCtx).Close(eventFactoryCtx, eventFactoryServer.request.Connection)
if closeErr != nil {
log.FromContext(ctx).Errorf("Can't close old connection: %v", closeErr)
}
eventFactoryServer.state = closed
eventFactoryCtxCancel()
}

withEventFactoryCtx := withEventFactory(ctx, eventFactoryServer)
conn, err = next.Server(withEventFactoryCtx).Request(withEventFactoryCtx, request)
if err != nil {
if eventFactoryServer.state != established {
Expand Down

0 comments on commit 01bb35f

Please sign in to comment.