-
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
Changes from 4 commits
107a789
d14a71d
d8f7077
983934c
b0778cd
6ff3c75
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ func NewClient() networkservice.NetworkServiceClient { | |
func (r *recvFDClient) Request(ctx context.Context, request *networkservice.NetworkServiceRequest, opts ...grpc.CallOption) (*networkservice.Connection, error) { | ||
// Get the grpcfd.FDRecver | ||
rpcCredentials := grpcfd.PerRPCCredentials(grpcfd.PerRPCCredentialsFromCallOptions(opts...)) | ||
opts = append(opts, grpc.PerRPCCredentials(rpcCredentials)) | ||
opts = append([]grpc.CallOption{grpc.PerRPCCredentials(rpcCredentials)}, opts...) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to change the order of call options? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My fault, I did a mistake during the testing, there is no need for this. |
||
recv, _ := grpcfd.FromPerRPCCredentials(rpcCredentials) | ||
|
||
// Call the next Client in the chain | ||
|
@@ -76,7 +76,7 @@ func (r *recvFDClient) Request(ctx context.Context, request *networkservice.Netw | |
func (r *recvFDClient) Close(ctx context.Context, conn *networkservice.Connection, opts ...grpc.CallOption) (*empty.Empty, error) { | ||
// Get the grpcfd.FDRecver | ||
rpcCredentials := grpcfd.PerRPCCredentials(grpcfd.PerRPCCredentialsFromCallOptions(opts...)) | ||
opts = append(opts, grpc.PerRPCCredentials(rpcCredentials)) | ||
opts = append([]grpc.CallOption{grpc.PerRPCCredentials(rpcCredentials)}, opts...) | ||
Bolodya1997 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
recv, _ := grpcfd.FromPerRPCCredentials(rpcCredentials) | ||
|
||
// Get the fileMap | ||
|
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 flag bool | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you use a more understandable name?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed with |
||||||
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) { | ||||||
flag = 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, flag) | ||||||
require.Equal(t, nse2, conn.NetworkServiceEndpointName) | ||||||
require.Equal(t, map[string]string{nse2: nse2}, conn.Labels) | ||||||
} |
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.