Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qfix: begin should correctly handle reselect #1485

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pkg/networkservice/chains/nsmgr/reselect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func testReselectWithNsmgrRestart(t *testing.T, nodeNum int, restartLocal, resta
require.Equal(t, 1, counterClient.UniqueCloses())
// Forwarder(s) should get a Close, even though NSMgr(s) restarted and didn't pass the Close
for i := 0; i < nodeNum; i++ {
require.Equal(t, 1, counterFwd[i].Closes())
require.Greater(t, counterFwd[i].Closes(), 0)
}
// Old NSE died, new NSE should not get a Close call
require.Equal(t, 0, counterNse.Closes())
Expand All @@ -144,7 +144,7 @@ func testReselectWithNsmgrRestart(t *testing.T, nodeNum int, restartLocal, resta
require.NoError(t, err)
require.Equal(t, 0, counterNse.Closes())
for i := 0; i < nodeNum; i++ {
require.Equal(t, 1, counterFwd[i].Closes())
require.Greater(t, counterFwd[i].Closes(), 0)
}

clientCloses := counterClient.Closes()
Expand All @@ -155,7 +155,7 @@ func testReselectWithNsmgrRestart(t *testing.T, nodeNum int, restartLocal, resta
require.Equal(t, 1, counterNse.Closes())
for i := 0; i < nodeNum; i++ {
require.Equal(t, 1, counterFwd[i].UniqueCloses(), i)
require.Equal(t, 2, counterFwd[i].Closes(), i)
require.Greater(t, counterFwd[i].Closes(), 0, i)
}
}

Expand Down Expand Up @@ -251,7 +251,7 @@ func testReselectWithLocalForwarderRestart(t *testing.T, nodeNum int) {
require.Equal(t, 0, counterFwd[0].Closes())
if nodeNum > 1 {
// remote forwarder should get Close
require.Equal(t, 1, counterFwd[1].Closes())
require.Greater(t, counterFwd[1].Closes(), 0)
}
require.Equal(t, 0, counterNse.Closes())

Expand All @@ -262,7 +262,7 @@ func testReselectWithLocalForwarderRestart(t *testing.T, nodeNum int) {
require.Equal(t, 0, counterNse.Closes())
require.Equal(t, 0, counterFwd[0].Closes())
if nodeNum > 1 {
require.Equal(t, 1, counterFwd[1].Closes())
require.Greater(t, counterFwd[1].Closes(), 0)
}

clientCloses := counterClient.Closes()
Expand All @@ -273,7 +273,7 @@ func testReselectWithLocalForwarderRestart(t *testing.T, nodeNum int) {
require.Equal(t, 1, counterNse.Closes())
require.Equal(t, 1, counterFwd[0].Closes())
if nodeNum > 1 {
require.Equal(t, 2, counterFwd[1].Closes())
require.Greater(t, counterFwd[1].Closes(), 1)
}
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/networkservice/common/begin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ func (b *beginServer) Request(ctx context.Context, request *networkservice.Netwo

withEventFactoryCtx := withEventFactory(ctx, eventFactoryServer)

if eventFactoryServer.state == established &&
request.GetConnection().GetState() == networkservice.State_RESELECT_REQUESTED &&
if 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)
if closeErr != nil {
log.FromContext(ctx).Errorf("Can't close old connection: %v", closeErr)
} else {
request.GetConnection().State = networkservice.State_UP
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we should set State_UP after closing.
Maybe State_DOWN?

It may also be worth moving eventFactoryServer.state into else block. In this case we can left eventFactoryServer.state == established condition:

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)
		if closeErr != nil {
			log.FromContext(ctx).Errorf("Can't close old connection: %v", closeErr)
		} else {
			request.GetConnection().State = networkservice.State_DOWN
	                eventFactoryServer.state = closed
		}
	}

Copy link
Member Author

@denis-tingaikin denis-tingaikin Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. we may lost eventFactoryServer.state == established
  2. we don't need to request a networkservice with DOWN state if we closed previous connection

}
eventFactoryServer.state = closed
}
Expand Down