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

Pr fix connect server #703

Merged
16 changes: 11 additions & 5 deletions pkg/networkservice/common/clienturl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import (
"context"
"sync"

"github.com/networkservicemesh/sdk/pkg/networkservice/chains/client"
"github.com/networkservicemesh/sdk/pkg/tools/clienturlctx"

"github.com/golang/protobuf/ptypes/empty"
"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/pkg/errors"
"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"

"github.com/networkservicemesh/api/pkg/api/networkservice"

"github.com/networkservicemesh/sdk/pkg/networkservice/chains/client"
"github.com/networkservicemesh/sdk/pkg/tools/clienturlctx"
"github.com/networkservicemesh/sdk/pkg/tools/grpcutils"
)

Expand Down Expand Up @@ -76,11 +76,16 @@ func (u *clientURLClient) init() error {
u.dialErr = errors.New("cannot dial nil clienturl.ClientURL(ctx)")
return
}

ctx, cancel := context.WithTimeout(u.ctx, dialTimeout)
Copy link
Member

Choose a reason for hiding this comment

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

Why are we introducing a new arbitrary dialTimeout instead of deriving it from the ctx of the request?

Copy link
Author

Choose a reason for hiding this comment

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

It will break discover + roundrobin, because it will wait for the first dial until requests lives and so there won't be any chance to try someone else.

defer cancel()

var cc *grpc.ClientConn
cc, u.dialErr = grpc.DialContext(u.ctx, grpcutils.URLToTarget(clientURL), u.dialOptions...)
cc, u.dialErr = grpc.DialContext(ctx, grpcutils.URLToTarget(clientURL), u.dialOptions...)
if u.dialErr != nil {
return
}

u.client = u.clientFactory(u.ctx, cc)

go func() {
Expand All @@ -97,5 +102,6 @@ func (u *clientURLClient) init() error {
}
}()
})

return u.dialErr
}
21 changes: 21 additions & 0 deletions pkg/networkservice/common/clienturl/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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 clienturl

import "time"

const dialTimeout = 100 * time.Millisecond
5 changes: 1 addition & 4 deletions pkg/networkservice/common/connect/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ return without error.
## connectServer

`connectServer` keeps `connInfos` [connectionInfoMap](https://github.com/networkservicemesh/pkg/networkservice/common/connect/gen.go#25)
mapping incoming server `Connection.ID` to the remote server URL and to the client chain assigned to this URL, and `clients` [clientmap.RefcountMap](https://github.com/networkservicemesh/sdk/blob/master/pkg/tools/clientmap/refcount.go)
mapping incoming server `Connection.ID` to the remote server URL and to the client chain assigned to this URL
mapping remote server URL to a [clienturl.NewClient(...)](https://github.com/networkservicemesh/sdk/blob/master/pkg/networkservice/common/clienturl/client.go)
which handles the instantiation and management of the client connection from the `clienturl.ClientURL(ctx)` of the server
Request. Notably, on every [clienturl.NewClient(...)](https://github.com/networkservicemesh/sdk/blob/master/pkg/networkservice/common/clienturl/client.go)
Expand All @@ -46,6 +46,3 @@ Concurrency is primarily managed through type-specific wrappers of [sync.Map](ht
> Go map paired with a separate Mutex or RWMutex.

This is precisely our case.

[clientmap.RefcountMap](https://github.com/networkservicemesh/sdk/blob/master/pkg/tools/clientmap/refcount.go#L43) utilizes
a simple atomic refcount, which is also highly performant.
44 changes: 0 additions & 44 deletions pkg/networkservice/common/connect/client.go

This file was deleted.

73 changes: 73 additions & 0 deletions pkg/networkservice/common/connect/client_info_map.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pkg/networkservice/common/connect/gen.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020 Doc.ai and/or its affiliates.
// Copyright (c) 2020-2021 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -21,5 +21,7 @@ import (
)

//go:generate go-syncmap -output connection_info_map.gen.go -type connectionInfoMap<string,connectionInfo>
//go:generate go-syncmap -output client_info_map.gen.go -type clientInfoMap<string,*clientInfo>

type connectionInfoMap sync.Map
type clientInfoMap sync.Map
Loading