apache / apache/cassandra-gocql-driver

CASSGO-5 `system.peers` queried even if `DisableInitialHostLookup` set to `true`

Open
#1,665 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
2.7k
Forks
658
PR merge metrics
No merged PRs in 30d

Description

### What version of Cassandra are you using?

We're actually using [AWS Keyspaces](https://aws.amazon.com/keyspaces/)

### What version of Gocql are you using?

The issue exists in `1.2.1`

### What version of Go are you using?

1.19

### What did you do?

Set the `DisableInitialHostLookup` to `true`

### What did you expect to see?

The driver would never query `system.peers` for host information

### What did you see instead?

On heartbeat failure, the driver tries to query `system.peers`.

---

Hi there,

Apologies in advance if this has been answered before - I searched through the issues and couldn't see anything related.

The [docs for the `DisableInitialHostLookup`](https://github.com/gocql/gocql/blob/6132f789ad22c1d19a66c58ac789402d5f1f9be5/cluster.go#L158-L163) config flag state:

> If DisableInitialHostLookup then the driver will not attempt to get host info from the `system.peers` table, this will mean that the driver will connect to hosts supplied and will not attempt to lookup the hosts information

It's true that the library avoids quering `system.peers` [on session initialization](https://github.com/gocql/gocql/blob/6132f789ad22c1d19a66c58ac789402d5f1f9be5/session.go#L216-L231) however, in the event of a heartbeat failure on the control connection, we [call `(*controlConn).reconnect` with the `refreshring` arg `true`](https://gkjithub.com/gocql/gocql/blob/6132f789ad22c1d19a66c58ac789402d5f1f9be5/control.go#L101). Which (as far as I can tell) will ultimately [query `system.peers`](https://github.com/gocql/gocql/blob/6132f789ad22c1d19a66c58ac789402d5f1f9be5/conn.go#L1623).

It seems to me that this is true to the _name_ of the config flag `DisableInitialHostLookup` but is not quite what the documentation suggests. I'm interested to know the maintainers' view on this and whether they'd consider a patch to change the reconnection logic to consider the `DisableInitialHostLookup` configuration. Perhaps something like this:

```
reconn:
// try to connect a bit faster
sleepTime = 1 * time.Second
refreshRing := !c.session.cfg.DisableInitialHostLookup
c.reconnect(refreshRing)
continue
}
```

## Why do we care?

A little bit more context to explain why this matters to us.

We're using gocql to speak to AWS Keyspaces, and, for various reasons, we don't want to grant the driver access to the `system.peers` table. We set the `DisableInitialHostLookup` flag to `false` but it seems that if we get a heartbeat timeout on a control connection, we'll try and refresh the ring and immediately run into this problem.

Contributor guide

Open the contributing guide

Research direction

Trace the reconnect path through session.go and control.go, then inspect the system.peers query in conn.go and the DisableInitialHostLookup definition in cluster.go. Verify how heartbeat failure calls controlConn.reconnect with refreshRing set to true. Done means the disabled setting prevents this system.peers lookup during heartbeat recovery while preserving the existing behavior when host lookup is enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, go
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.