{"record":{"id":"707afb3d809824fc","repo":"apache/cassandra","slug":"failed-to-create-client-too-many-times","errorCode":null,"errorMessage":"Failed to create client too many times","messagePattern":"Failed to create client too many times","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"tools/stress/src/org/apache/cassandra/stress/settings/StressSettings.java","lineNumber":138,"sourceCode":"    {\n        if (setKeyspace)\n        {\n            return getJavaDriverClient(schema.keyspace);\n        } else {\n            return getJavaDriverClient(null);\n        }\n    }\n\n\n    public JavaDriverClient getJavaDriverClient(String keyspace)\n    {\n        if (client != null)\n            return client;\n\n        synchronized (this)\n        {\n            if (numFailures >= MAX_NUM_FAILURES)\n                throw new RuntimeException(\"Failed to create client too many times\");\n\n            try\n            {\n                if (client != null)\n                    return client;\n\n                EncryptionOptions.ClientEncryptionOptions encOptions = transport.getEncryptionOptions();\n                JavaDriverClient c = new JavaDriverClient(this, node.nodes, port.nativePort, encOptions);\n                c.connect(mode.compression());\n                if (keyspace != null)\n                    c.execute(\"USE \\\"\" + keyspace + \"\\\";\", org.apache.cassandra.db.ConsistencyLevel.ONE);\n\n                return client = c;\n            }\n            catch (Exception e)\n            {\n                numFailures +=1;\n                throw new RuntimeException(e);","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/tools/stress/src/org/apache/cassandra/stress/settings/StressSettings.java#L120-L156","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the target node is up and native transport is running (nodetool status, netstat on 9042)","Check -node and -port options match the cluster","Confirm auth credentials in -mode user=/password= and SSL settings in -transport match server config","Inspect earlier log lines for the underlying driver exception per attempt"],"exampleFix":"// before\ncassandra-stress write -node 10.0.0.99   # node down\n// after\ncassandra-stress write -node 10.0.0.10,10.0.0.11","handlingStrategy":"retry","validationCode":"try (Socket s = new Socket()) { s.connect(new InetSocketAddress(host, 9042), 3000); } // probe native port first","typeGuard":null,"tryCatchPattern":"try { client = settings.getJavaDriverClient(); }\ncatch (RuntimeException e) {\n  if (e.getMessage().contains(\"Failed to create client too many times\")) {\n    checkNodeUp(); checkPort(); checkTlsAndAuth(); // inspect per-attempt cause in logs\n  } else throw e;\n}","preventionTips":["Probe the native transport port before launching long stress runs","Point -node at multiple healthy nodes","Match -mode credentials and -transport SSL settings to server config","Wait for nodes to finish bootstrap/startup before stressing"],"tags":["network","driver","connection"],"backgroundTag":"connection-refused","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}