-
Notifications
You must be signed in to change notification settings - Fork 36
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
[sdk#1111] Fix sendfd
issue on URL change
#1112
Merged
edwarnicke
merged 6 commits into
networkservicemesh:main
from
Bolodya1997:qfix/clien-chain-dial
Oct 20, 2021
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
107a789
Set dial client before additional functionality in client chain
d14a71d
Fix recvfd/senfd clients
d8f7077
Clone request in remote iteration points
983934c
Add multiforwarder sendfd test
b0778cd
Revert "Fix recvfd/senfd clients"
6ff3c75
Fix naming
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
// Copyright (c) 2020-2021 Doc.ai and/or its affiliates. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at: | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//+build !windows | ||
|
||
package nsmgr_test | ||
|
||
import ( | ||
"context" | ||
"runtime" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
"go.uber.org/goleak" | ||
|
||
"github.com/networkservicemesh/api/pkg/api/registry" | ||
|
||
"github.com/networkservicemesh/sdk/pkg/networkservice/chains/nsmgr" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/kernel" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/recvfd" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/sendfd" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/count" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/inject/injecterror" | ||
"github.com/networkservicemesh/sdk/pkg/tools/sandbox" | ||
) | ||
|
||
func Test_Local_NoURLUsecase(t *testing.T) { | ||
t.Cleanup(func() { goleak.VerifyNone(t) }) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) | ||
defer cancel() | ||
|
||
domain := sandbox.NewBuilder(ctx, t). | ||
UseUnixSockets(). | ||
Build() | ||
|
||
nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.GenerateTestToken) | ||
|
||
nsReg, err := nsRegistryClient.Register(ctx, defaultRegistryService()) | ||
require.NoError(t, err) | ||
|
||
nseReg := defaultRegistryEndpoint(nsReg.Name) | ||
request := defaultRequest(nsReg.Name) | ||
counter := new(count.Server) | ||
|
||
domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken, counter) | ||
|
||
nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken) | ||
|
||
conn, err := nsc.Request(ctx, request.Clone()) | ||
require.NoError(t, err) | ||
require.NotNil(t, conn) | ||
require.Equal(t, 1, counter.Requests()) | ||
require.Equal(t, 5, len(conn.Path.PathSegments)) | ||
|
||
// Simulate refresh from client | ||
refreshRequest := request.Clone() | ||
refreshRequest.Connection = conn.Clone() | ||
|
||
conn2, err := nsc.Request(ctx, refreshRequest) | ||
require.NoError(t, err) | ||
require.NotNil(t, conn2) | ||
require.Equal(t, 5, len(conn2.Path.PathSegments)) | ||
require.Equal(t, 2, counter.Requests()) | ||
|
||
// Close | ||
_, err = nsc.Close(ctx, conn) | ||
require.NoError(t, err) | ||
require.Equal(t, 1, counter.Closes()) | ||
} | ||
|
||
func Test_MultiForwarderSendfd(t *testing.T) { | ||
if runtime.GOOS != "linux" { | ||
t.Skip("sendfd works only on linux") | ||
} | ||
t.Cleanup(func() { goleak.VerifyNone(t) }) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) | ||
defer cancel() | ||
|
||
errorServer := injecterror.NewServer( | ||
injecterror.WithRequestErrorTimes(0), | ||
injecterror.WithCloseErrorTimes(), | ||
) | ||
domain := sandbox.NewBuilder(ctx, t). | ||
UseUnixSockets(). | ||
SetNodeSetup(func(ctx context.Context, node *sandbox.Node, _ int) { | ||
node.NewNSMgr(ctx, "nsmgr", nil, sandbox.GenerateTestToken, nsmgr.NewServer) | ||
node.NewForwarder(ctx, ®istry.NetworkServiceEndpoint{ | ||
Name: "forwarder-1", | ||
}, sandbox.GenerateTestToken, errorServer, recvfd.NewServer()) | ||
node.NewForwarder(ctx, ®istry.NetworkServiceEndpoint{ | ||
Name: "forwarder-2", | ||
}, sandbox.GenerateTestToken, errorServer, recvfd.NewServer()) | ||
}). | ||
Build() | ||
|
||
nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.GenerateTestToken) | ||
|
||
nsReg, err := nsRegistryClient.Register(ctx, defaultRegistryService()) | ||
require.NoError(t, err) | ||
|
||
nseReg := defaultRegistryEndpoint(nsReg.Name) | ||
counter := new(count.Server) | ||
|
||
domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken, counter) | ||
|
||
nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, kernel.NewClient(), sendfd.NewClient()) | ||
|
||
request := defaultRequest(nsReg.Name) | ||
|
||
conn, err := nsc.Request(ctx, request.Clone()) | ||
require.NoError(t, err) | ||
require.NotNil(t, conn) | ||
require.Equal(t, 1, counter.Requests()) | ||
require.Equal(t, 5, len(conn.Path.PathSegments)) | ||
|
||
// Simulate refresh from client | ||
refreshRequest := request.Clone() | ||
refreshRequest.Connection = conn.Clone() | ||
|
||
conn2, err := nsc.Request(ctx, refreshRequest) | ||
require.NoError(t, err) | ||
require.NotNil(t, conn2) | ||
require.Equal(t, 5, len(conn2.Path.PathSegments)) | ||
require.Equal(t, 2, counter.Requests()) | ||
|
||
// Close | ||
_, err = nsc.Close(ctx, conn) | ||
require.NoError(t, err) | ||
require.Equal(t, 1, counter.Closes()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright (c) 2021 Doc.ai and/or its affiliates. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at: | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package roundrobin_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"go.uber.org/goleak" | ||
|
||
"github.com/networkservicemesh/api/pkg/api/networkservice" | ||
"github.com/networkservicemesh/api/pkg/api/registry" | ||
|
||
"github.com/networkservicemesh/sdk/pkg/networkservice/common/discover" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/common/roundrobin" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/common/switchcase" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/core/next" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/checks/checkrequest" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/inject/injecterror" | ||
) | ||
|
||
const ( | ||
nse1 = "nse-1" | ||
nse2 = "nse-2" | ||
ns = "ns" | ||
) | ||
|
||
func TestSelectEndpointServer_CleanRequest(t *testing.T) { | ||
Bolodya1997 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
t.Cleanup(func() { goleak.VerifyNone(t) }) | ||
|
||
var hasBeenRequested bool | ||
s := next.NewNetworkServiceServer( | ||
roundrobin.NewServer(), | ||
switchcase.NewServer( | ||
&switchcase.ServerCase{ | ||
Condition: func(_ context.Context, conn *networkservice.Connection) bool { | ||
return conn.NetworkServiceEndpointName == nse1 | ||
}, | ||
Server: next.NewNetworkServiceServer( | ||
checkrequest.NewServer(t, func(_ *testing.T, request *networkservice.NetworkServiceRequest) { | ||
hasBeenRequested = true | ||
request.Connection.Labels[nse1] = nse1 | ||
}), | ||
injecterror.NewServer(), | ||
), | ||
}, | ||
), | ||
) | ||
|
||
ctx := discover.WithCandidates(context.Background(), []*registry.NetworkServiceEndpoint{ | ||
{ | ||
Name: nse1, | ||
Url: "unix://" + nse1, | ||
NetworkServiceNames: []string{ns}, | ||
}, | ||
{ | ||
Name: nse2, | ||
Url: "unix://" + nse2, | ||
NetworkServiceNames: []string{ns}, | ||
}, | ||
}, ®istry.NetworkService{Name: ns}) | ||
|
||
conn, err := s.Request(ctx, &networkservice.NetworkServiceRequest{ | ||
Connection: &networkservice.Connection{ | ||
Labels: map[string]string{nse2: nse2}, | ||
}, | ||
}) | ||
require.NoError(t, err) | ||
|
||
require.True(t, hasBeenRequested) | ||
require.Equal(t, nse2, conn.NetworkServiceEndpointName) | ||
require.Equal(t, map[string]string{nse2: nse2}, conn.Labels) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to change this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case of URL change
dial.Client
does the following on Request:If we have
sendfd.Client
in the chain before it does the following on Request:grpcfd.PerRPCCredentials
to the call options.grpcfd.PerRPCCredentials
does the following:FDTransceiver
.So it results in the following:
dial
closes old URL -PerRPCCredentials
sends all fds to the old URL.dial
requests new URL -PerRPCCredentials
has nothing to send so it does nothing.So here are 2 solutions that I can currently see:
dial
client beforeadditionalFunctionality
.PerRPCCredentials
not to captureFDTransceiver
and not to cleanup stored fds on send.We have discussed this with @edwarnicke and so it actually looks like both of these solutions have their pros and cons, but [1] is easier to implement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@denis-tingaikin I discussed this this morning with @Bolodya1997 on slack. It's a subtle bug, but once explained it makes sense.