Skip to content

Conversation

amcrn
Copy link

@amcrn amcrn commented Sep 14, 2023

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.

This also fixes an issue if disableControlConn=true and/or DisableInitialHostLookup=true, where the Ring is updated with the host, prior to filtering:
https://github.com/gocql/gocql/blob/db6d5564dd6843cc08cc1d6c3642612adf94c618/session.go#L265-L268

Closes: #1723

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.
// 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.

@testisnullus
Copy link

LGTM

Copy link
Contributor

@OleksiienkoMykyta OleksiienkoMykyta left a comment

Choose a reason for hiding this comment

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

LGTM. Could you please make it up to date, update CHANGELOG.md, and refactor commit log according to CONTRIBUTING.md, as an example you can check f35d463, or any other last merged PR.
@joao-r-reis, @jameshartig, please check it out.

@jameshartig
Copy link
Contributor

jameshartig commented Mar 14, 2025

Unfortunately, I don't think this is the right way for this to be fixed. The problem is that most HostFilter's expect the information about the host to be filled in (such as DataCenter, ConnectAddress, HostID), but in this case, so early in the process we don't have the correct, or really any information. I'm concerned that this will be pointless (because they'll all be filtered) and very confusing.

Right after we connect, we filter the hosts which seems about as good as we can do.

filteredHosts := make([]*HostInfo, 0, len(newHosts))

This also fixes an issue if disableControlConn=true and/or DisableInitialHostLookup=true, where the Ring is updated with the host, prior to filtering:

My understanding is that the ring should always contain all hosts in the cluster and that we should only be filtering before adding a host to the pool so I believe this is working as intended.

@joao-r-reis
Copy link
Contributor

This also fixes an issue if disableControlConn=true and/or DisableInitialHostLookup=true, where the Ring is updated with the host, prior to filtering:

My understanding is that the ring should always contain all hosts in the cluster and that we should only be filtering before adding a host to the pool so I believe this is working as intended.

There's a separate PR to address the issue with DisableInitialHostLookup=true, I posted this comment there. Are your thoughts in line with what my suggestion there @jameshartig ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HostFilter Not Used for Control Connection

5 participants