@@ -109,6 +109,7 @@ type (
109109 balancerWithMeta struct {
110110 balancer * balancer.Balancer
111111 meta * meta.Meta
112+ close func (ctx context.Context ) error
112113 }
113114)
114115
@@ -134,6 +135,10 @@ func (b *balancerWithMeta) NewStream(ctx context.Context, desc *grpc.StreamDesc,
134135 return b .balancer .NewStream (metaCtx , desc , method , opts ... )
135136}
136137
138+ func (b * balancerWithMeta ) Close (ctx context.Context ) error {
139+ return b .close (ctx )
140+ }
141+
137142// Close closes Driver and clear resources
138143//
139144//nolint:nonamedreturns
@@ -176,7 +181,7 @@ func (d *Driver) Close(ctx context.Context) (finalErr error) {
176181 d .query .Close ,
177182 d .topic .Close ,
178183 d .discovery .Close ,
179- d .metaBalancer .balancer . Close ,
184+ d .metaBalancer .Close ,
180185 d .pool .Release ,
181186 )
182187
@@ -278,7 +283,7 @@ func Open(ctx context.Context, dsn string, opts ...Option) (_ *Driver, _ error)
278283 }
279284 }
280285
281- d , err := newConnectionFromOptions (ctx , opts ... )
286+ d , err := driverFromOptions (ctx , opts ... )
282287 if err != nil {
283288 return nil , xerrors .WithStackTrace (err )
284289 }
@@ -320,7 +325,7 @@ func MustOpen(ctx context.Context, dsn string, opts ...Option) *Driver {
320325// Will be removed after Oct 2024.
321326// Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated
322327func New (ctx context.Context , opts ... Option ) (_ * Driver , err error ) { //nolint:nonamedreturns
323- d , err := newConnectionFromOptions (ctx , opts ... )
328+ d , err := driverFromOptions (ctx , opts ... )
324329 if err != nil {
325330 return nil , xerrors .WithStackTrace (err )
326331 }
@@ -342,7 +347,7 @@ func New(ctx context.Context, opts ...Option) (_ *Driver, err error) { //nolint:
342347}
343348
344349//nolint:cyclop, nonamedreturns, funlen
345- func newConnectionFromOptions (ctx context.Context , opts ... Option ) (_ * Driver , err error ) {
350+ func driverFromOptions (ctx context.Context , opts ... Option ) (_ * Driver , err error ) {
346351 ctx , driverCtxCancel := xcontext .WithCancel (xcontext .ValueOnly (ctx ))
347352 defer func () {
348353 if err != nil {
@@ -444,6 +449,7 @@ func (d *Driver) connect(ctx context.Context) (err error) {
444449 return xerrors .WithStackTrace (err )
445450 }
446451 d .metaBalancer .balancer = b
452+ d .metaBalancer .close = b .Close
447453 }
448454 d .metaBalancer .meta = d .config .Meta ()
449455
0 commit comments