DataStax C# Driver: Default cluster name cache causes incorrect connections across Cassandra instances

10 views
Skip to first unread message

Andre Hofmeister

unread,
Apr 29, 2025, 12:02:26 PMApr 29
to DataStax C# Driver for Apache Cassandra User Mailing List
Hi,

we're running into a race-condition with the DataStax C# driver for Apache Cassandra, and I believe this is a general issue with the client implementation.

We're running multiple Apache Cassandra containers on the same host. It looks like the client caches connections based on the cluster name. If the connection string doesn't specify a cluster name, it uses the default cluster name.

Here's what happens:
  1. Create an Apache Cassandra instance listening on localhost:51732 (container_1).
  2. Create an Apache Cassandra instance listening on localhost:51742 (container_2).
  3. Create a CqlConnection instance for container_1.
    1. This creates a connection using the default cluster name: Cassandra Cluster.
  4. Run tests against container_1, and tear it down afterwards.
  5. Create a CqlConnection instance for container_2.
    1. This is where the race-condition happens. It looks like the client implementation still tries to connect to container_1, even though the connection string is correctly set for container_2.
    2. This could even lead to false assumptions. For example, if we didn't tear down container_1 beforehand, the client might end up connecting to the wrong instance.
    3. From a quick look at the code, it seems like the cluster name is never removed from the internal dictionary during Close() or Dispose().
Is this desired? Any recommendations or guidance on how to deal with it?

Best

Andre
Reply all
Reply to author
Forward
0 new messages