Skip to content

Commit

Permalink
add mutexes to dialer
Browse files Browse the repository at this point in the history
Signed-off-by: NikitaSkrynnik <[email protected]>
  • Loading branch information
NikitaSkrynnik committed Dec 3, 2024
1 parent 1448e7b commit 6c00f3d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/networkservice/common/dial/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"net/url"
"runtime"
"sync"
"time"

"github.com/pkg/errors"
Expand All @@ -37,6 +38,8 @@ type dialer struct {
*grpc.ClientConn
dialOptions []grpc.DialOption
dialTimeout time.Duration

mu sync.Mutex
}

func newDialer(ctx context.Context, dialTimeout time.Duration, dialOptions ...grpc.DialOption) *dialer {
Expand Down Expand Up @@ -74,7 +77,9 @@ func (di *dialer) Dial(ctx context.Context, clientURL *url.URL) error {
}
return errors.Wrapf(err, "failed to dial %s", target)
}
di.mu.Lock()
di.ClientConn = cc
di.mu.Unlock()

di.cleanupContext, di.cleanupCancel = context.WithCancel(di.ctx)

Expand All @@ -101,6 +106,8 @@ func (di *dialer) Invoke(ctx context.Context, method string, args, reply interfa
}

func (di *dialer) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, opts ...grpc.CallOption) (grpc.ClientStream, error) {
di.mu.Lock()
defer di.mu.Unlock()
if di.ClientConn == nil {
return nil, errors.New("no dialer.ClientConn found")
}
Expand Down

0 comments on commit 6c00f3d

Please sign in to comment.