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

Fix nil pointer dereference in meta balancer initialization #1540

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Fixed nil pointer dereference in metabalancer initialization

## v3.89.4
* Changed behaviour on re-discovery: always open new grpc connection for discovery request

Expand Down
11 changes: 7 additions & 4 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,9 @@ func newConnectionFromOptions(ctx context.Context, opts ...Option) (_ *Driver, e
}()

d := &Driver{
children: make(map[uint64]*Driver),
ctxCancel: driverCtxCancel,
children: make(map[uint64]*Driver),
ctxCancel: driverCtxCancel,
metaBalancer: &balancerWithMeta{},
}

if caFile, has := os.LookupEnv("YDB_SSL_ROOT_CERTIFICATES_FILE"); has {
Expand Down Expand Up @@ -436,13 +437,15 @@ func (d *Driver) connect(ctx context.Context) (err error) {
if d.pool == nil {
d.pool = conn.NewPool(ctx, d.config)
}
if d.metaBalancer == nil {

if d.metaBalancer.balancer == nil {
b, err := balancer.New(ctx, d.config, d.pool, d.discoveryOptions...)
if err != nil {
return xerrors.WithStackTrace(err)
}
d.metaBalancer = &balancerWithMeta{balancer: b, meta: d.config.Meta()}
d.metaBalancer.balancer = b
}
d.metaBalancer.meta = d.config.Meta()

d.table = xsync.OnceValue(func() (*internalTable.Client, error) {
return internalTable.New(xcontext.ValueOnly(ctx),
Expand Down
2 changes: 1 addition & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ func WithPanicCallback(panicCallback func(e interface{})) Option {
// WithSharedBalancer sets balancer from parent driver to child driver
func WithSharedBalancer(parent *Driver) Option {
return func(ctx context.Context, d *Driver) error {
d.metaBalancer = &balancerWithMeta{balancer: parent.metaBalancer.balancer, meta: d.config.Meta()}
d.metaBalancer.balancer = parent.metaBalancer.balancer

return nil
}
Expand Down
Loading