Skip to content

Commit

Permalink
fix(scyllaclient): don't panic on empty host in client
Browse files Browse the repository at this point in the history
In case client was mistakenly initialized with "" host, getting host from the pool would panic:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x11da5ac]
goroutine 253 [running]:
github.com/scylladb/scylla-manager/v3/pkg/scyllaclient.NewClient.hostPool.func3(0xc0004345a0)
github.com/scylladb/scylla-manager/v3/pkg/scyllaclient/hostpool.go:32 +0xac

This should be replaced with a simple error.
This commit adds additional validation to client config,
which prohibits specifying empty host there.
It also makes host pool return an error instead of panic
in case of invalid host pool response.

Fixes scylladb/scylla-enterprise#4692
  • Loading branch information
Michal-Leszczynski authored and karol-kokoszka committed Sep 11, 2024
1 parent ed87d32 commit f0faa48
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/scyllaclient/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package scyllaclient

import (
"net/http"
"slices"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -111,6 +112,9 @@ func (c Config) Validate() error {
if len(c.Hosts) == 0 {
err = multierr.Append(err, errors.New("missing hosts"))
}
if slices.Contains(c.Hosts, "") {
err = multierr.Append(err, errors.New("empty host"))
}
if c.Port == "" {
err = multierr.Append(err, errors.New("missing port"))
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/scyllaclient/hostpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ func hostPool(next http.RoundTripper, pool hostpool.HostPool, port string) http.
// Get host from pool
if !ok {
hpr = pool.Get()
if hpr == nil {
return nil, errors.New("empty host pool response")
}
h = hpr.Host()
}

Expand Down

0 comments on commit f0faa48

Please sign in to comment.