From 1239ed49cf56d19329c9bf951e92c34a5798445b Mon Sep 17 00:00:00 2001 From: Auston Date: Thu, 14 Sep 2023 13:56:02 -0700 Subject: [PATCH] Update session.go The `HostFilter` is not being used for the Control Connection (aka the `controlConn`). This can be problematic, especially if the host is being filtered due to it being in a bad state, as it can hold up the creation of the Control Connection (and therefore the Session itself) for quite some time. --- session.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/session.go b/session.go index 0eac4cf0e..fcb068b49 100644 --- a/session.go +++ b/session.go @@ -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)) + 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 {