Skip to content
Open
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
16 changes: 16 additions & 0 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,22 @@ func (s *Session) init() error {
}
s.ring.endpoints = hosts

// filter hosts at the onset to avoid using using filtered hosts in the control connection while
// discovering the protocol and/or connecting.
if s.cfg.HostFilter != nil {
newHosts := make([]*HostInfo, 0, len(hosts))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can refactor to something like:

newHosts := hosts[:0]

to avoid allocating a new slice, but in general, it is a good suggestion to fix an issue.

for _, host := range hosts {
if !s.cfg.filterHost(host) {
newHosts = append(newHosts, host)
}
}
if len(newHosts) > 0 {
hosts = newHosts
} else {
s.logger.Printf("gocql: hostfilter removed all hosts, defaulting to initial host list\n")
}
}

if !s.cfg.disableControlConn {
s.control = createControlConn(s)
if s.cfg.ProtoVersion == 0 {
Expand Down