apache/cassandra · critical · RuntimeException

Failed to create client too many times

Error message

Failed to create client too many times

What it means

getJavaDriverClient retries driver Session/Cluster creation up to MAX_NUM_FAILURES times; when every attempt fails it throws RuntimeException 'Failed to create client too many times' instead of retrying forever. The real cause of each failure is logged during the attempts.

Solutions

  1. Verify the target node is up and native transport is running (nodetool status, netstat on 9042)
  2. Check -node and -port options match the cluster
  3. Confirm auth credentials in -mode user=/password= and SSL settings in -transport match server config
  4. Inspect earlier log lines for the underlying driver exception per attempt

Example fix

// before
cassandra-stress write -node 10.0.0.99   # node down
// after
cassandra-stress write -node 10.0.0.10,10.0.0.11
Defensive patterns

Strategy: retry

Validate before calling

try (Socket s = new Socket()) { s.connect(new InetSocketAddress(host, 9042), 3000); } // probe native port first

Try / catch

try { client = settings.getJavaDriverClient(); }
catch (RuntimeException e) {
  if (e.getMessage().contains("Failed to create client too many times")) {
    checkNodeUp(); checkPort(); checkTlsAndAuth(); // inspect per-attempt cause in logs
  } else throw e;
}

Prevention

When it happens

Trigger: Repeated failures to connect via the native driver during StressSettings.getJavaDriverClient: host unreachable, wrong port, TLS mismatch, auth rejection, or driver unable to resolve contact point.

Common situations: Stress pointing at a node that is down or still bootstrapping, wrong -node/-port values, SSL configured on server but not in stress (or vice versa), firewall blocking native transport port 9042.

Understand the failure class

Background: ECONNREFUSED and "connection refused" / "could not connect to server" errors: what they mean and how to fix them — this error's family across 44 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/707afb3d809824fc. Report an issue: GitHub.

Appendix: source

Thrown at tools/stress/src/org/apache/cassandra/stress/settings/StressSettings.java:138

    {
        if (setKeyspace)
        {
            return getJavaDriverClient(schema.keyspace);
        } else {
            return getJavaDriverClient(null);
        }
    }


    public JavaDriverClient getJavaDriverClient(String keyspace)
    {
        if (client != null)
            return client;

        synchronized (this)
        {
            if (numFailures >= MAX_NUM_FAILURES)
                throw new RuntimeException("Failed to create client too many times");

            try
            {
                if (client != null)
                    return client;

                EncryptionOptions.ClientEncryptionOptions encOptions = transport.getEncryptionOptions();
                JavaDriverClient c = new JavaDriverClient(this, node.nodes, port.nativePort, encOptions);
                c.connect(mode.compression());
                if (keyspace != null)
                    c.execute("USE \"" + keyspace + "\";", org.apache.cassandra.db.ConsistencyLevel.ONE);

                return client = c;
            }
            catch (Exception e)
            {
                numFailures +=1;
                throw new RuntimeException(e);

View on GitHub (pinned to 88fd0f6a0e)