Skip to content

Commit 7eb8e77

Browse files
authored
Merge branch 'master' into issue551
2 parents 26b91f2 + 4d70eab commit 7eb8e77

File tree

4 files changed

+21
-25
lines changed

4 files changed

+21
-25
lines changed

config/config.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ func (c Config) ExcludeGRPCCodesForPessimization() []grpcCodes.Code {
4646

4747
// GrpcDialOptions reports about used grpc dialing options
4848
func (c Config) GrpcDialOptions() []grpc.DialOption {
49-
return c.grpcOptions
49+
return append(
50+
defaultGrpcOptions(c.trace, c.secure, c.tlsConfig),
51+
c.grpcOptions...,
52+
)
5053
}
5154

5255
// Meta reports meta information about database connection
@@ -265,8 +268,6 @@ func New(opts ...Option) Config {
265268
}
266269
}
267270

268-
c.grpcOptions = append(defaultGrpcOptions(c.trace, c.secure, c.tlsConfig), c.grpcOptions...)
269-
270271
c.meta = meta.New(c.database, c.credentials, c.trace, c.metaOptions...)
271272

272273
return c

connection.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,6 @@ func connect(ctx context.Context, c *connection) error {
443443
onDone(err)
444444
}()
445445

446-
if c.pool == nil {
447-
c.pool = conn.NewPool(c.config)
448-
}
449-
450446
if c.userInfo != nil {
451447
c.config = c.config.With(config.WithCredentials(
452448
credentials.NewStaticCredentials(
@@ -457,7 +453,11 @@ func connect(ctx context.Context, c *connection) error {
457453
))
458454
}
459455

460-
c.balancer, err = balancer.New(ctx, c.config, c.pool, c.discoveryOptions...)
456+
if c.pool == nil {
457+
c.pool = conn.NewPool(c.config)
458+
}
459+
460+
c.balancer, err = balancer.New(ctx, c.config, c.pool, c.discoveryOptions...)
461461
if err != nil {
462462
return xerrors.WithStackTrace(err)
463463
}

internal/conn/conn.go

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ func (c *conn) Address() string {
5353
type conn struct {
5454
mtx sync.RWMutex
5555
config Config // ro access
56-
grpcDialOptions []grpc.DialOption
5756
cc *grpc.ClientConn
5857
done chan struct{}
5958
endpoint endpoint.Endpoint // ro access
@@ -200,7 +199,11 @@ func (c *conn) take(ctx context.Context) (cc *grpc.ClientConn, err error) {
200199
// three slashes in "ydb:///" is ok. It needs for good parse scheme in grpc resolver.
201200
address := "ydb:///" + c.endpoint.Address()
202201

203-
cc, err = grpc.DialContext(ctx, address, c.grpcDialOptions...)
202+
cc, err = grpc.DialContext(ctx, address, append(
203+
[]grpc.DialOption{
204+
grpc.WithStatsHandler(statsHandler{}),
205+
}, c.config.GrpcDialOptions()...,
206+
)...)
204207
if err != nil {
205208
err = xerrors.WithStackTrace(
206209
xerrors.Retryable(
@@ -461,20 +464,11 @@ func withOnTransportError(onTransportError func(ctx context.Context, cc Conn, ca
461464
}
462465

463466
func newConn(e endpoint.Endpoint, config Config, opts ...option) *conn {
464-
grpcDialOptions := config.GrpcDialOptions()
465-
grpcDialOptions = append(
466-
append(
467-
make([]grpc.DialOption, 0, len(grpcDialOptions)+1),
468-
statsHandlerOption,
469-
),
470-
grpcDialOptions...,
471-
)
472467
c := &conn{
473-
grpcDialOptions: grpcDialOptions,
474-
state: uint32(Created),
475-
endpoint: e,
476-
config: config,
477-
done: make(chan struct{}),
468+
state: uint32(Created),
469+
endpoint: e,
470+
config: config,
471+
done: make(chan struct{}),
478472
}
479473
for _, o := range opts {
480474
if o != nil {
@@ -493,8 +487,6 @@ var _ stats.Handler = statsHandler{}
493487

494488
type statsHandler struct{}
495489

496-
var statsHandlerOption = grpc.WithStatsHandler(statsHandler{})
497-
498490
func (statsHandler) TagRPC(ctx context.Context, _ *stats.RPCTagInfo) context.Context {
499491
return ctx
500492
}

internal/dsn/dsn.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ func Parse(dsn string) (info parsedInfo, err error) {
5050
if err != nil {
5151
return info, xerrors.WithStackTrace(err)
5252
}
53+
if port := uri.Port(); port == "" {
54+
return info, xerrors.WithStackTrace(fmt.Errorf("bad connection string '%s': port required", dsn))
55+
}
5356
info.Endpoint = uri.Host
5457
info.Database = uri.Path
5558
info.Secure = uri.Scheme != insecureSchema

0 commit comments

Comments
 (0)