Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cql-proxy is not removing quotes from the keyspace in set_keyspace responses which can confuse some drivers #128

Open
absurdfarce opened this issue Jun 25, 2024 · 0 comments · May be fixed by #129

Comments

@absurdfarce
Copy link
Collaborator

Issue originally identified and described by @ikehara in #127. The description of the problem is based on that work but the analysis of the root cause offered below is entirely my responsibility.

For the example below we'll assume version 3.29.1 of the DataStax Python driver for Apache Cassandra. Let's assume the following sequence of operations:

Recall that the keyspace argument passed through these functions is extracted directly from the set_keyspace result message. This value is just a basic string, but crucially it's provided from the server... meaning it represents a keyspace that has already been created (and thus must have a name matching the rules for keyspace names in Cassandra). As a result this name is just the string; there's no need to quote it or otherwise make it compatible with naming conventions.

To prove this you can run a simple Python client which executes a "USE [keyspace]" operation and monitor the traffic via Wireshark. Let's assume valid existing keyspaces on a Cassandra 4.0.2 server for what follows... at least that's what I tested all this on. Anyway, if you execute "use foo" and add some debugging you'll see the name "foo" returned in the set_keyspace result message. If you instead execute "use \"FOO\"" you'll see the name "FOO" returned via the result message. We had to wrap the value in double-quotes to clearly distinguish it from the lower-case keyspace but there's no need to do so when building the result message so it's just not done.

cql-proxy behaves slightly differently. When it builds it's set_keyspace result message it copies the value it parsed from the incoming statement. This means any double-quotes in the statement are also included in the message, which in turn leads to a follow-up "USE" statement from the driver which contains two double-quotes. This is a legit syntax error which means the cql-proxy parser fails with an error like this one:

{"level":"error","ts":1719267335.330605,"caller":"proxycore/connpool.go:74","msg":"unable to connect pool","host":"127.0.0.1:9042","error":"cql error: ERROR SYNTAX ERROR (code=ErrorCode SyntaxError [0x00002000], msg=line 1:4 no viable alternative at input '\"\"' (USE [\"\"]))","stacktrace":"github.com/datastax/cql-proxy/proxycore.connectPool\n\t/work/git/cql-proxy/proxycore/connpool.go:74\ngithub.com/datastax/cql-proxy/proxycore.(*Session).OnEvent.func1.1\n\t/work/git/cql-proxy/proxycore/session.go:120"}

Simply making the cql-proxy set_keyspace result message behave like the Cassandra version appears to completely address the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant