com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: host:9042 (com.datastax.driver.core.exceptions.TransportException: [null] Cannot connect))

DataStax JIRA | Andrew Jorgensen | 10 months ago
  1. 0

    Given the following java example: {code} try { List<InetSocketAddress> addresses = Lists.newArrayList(); addresses.add(InetSocketAddress.createUnresolved("host", 9042)); Session session = Cluster.builder().addContactPointsWithPorts(addresses).build().connect("batch_data"); ResultSet execute = session.execute("SELECT * FROM dnd LIMIT 1"); System.out.println("Result: " + execute.one()); } catch (Exception e) { e.printStackTrace(System.out); } try{ Session session = Cluster.builder().addContactPoint("host").withPort(9042).build().connect("batch_data"); ResultSet execute = session.execute("SELECT * FROM dnd LIMIT 1"); System.out.println("Result: " + execute.one()); } catch (Exception e) { e.printStackTrace(System.out); } {code} Results in the following: {code} com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: host:9042 (com.datastax.driver.core.exceptions.TransportException: [null] Cannot connect)) at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:231) at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:77) at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1382) at com.datastax.driver.core.Cluster.init(Cluster.java:162) at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:333) at com.datastax.driver.core.Cluster.connect(Cluster.java:283) at com.crashlytics.pump.Main.main(Main.java:21) Result: null {code} The first run through results in a NoHostAvailableException and the second run through successfully connects and executes the query (in this case returning no results). These two pieces of code feel like they should do the same thing to me. We are migrating from the old hector client which would take an argument in the form of "hostname[:port],[hostname[:port]...]" and correctly connect to the supplied nodes. With the Cluster builder it looks like the only options are to send in all the hosts as a string and set the port with .withPort() or to pass a collection of InetSocketAddress objects which have both the host and the port specified.

    DataStax JIRA | 10 months ago | Andrew Jorgensen
    com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: host:9042 (com.datastax.driver.core.exceptions.TransportException: [null] Cannot connect))
  2. 0

    Given the following java example: {code} try { List<InetSocketAddress> addresses = Lists.newArrayList(); addresses.add(InetSocketAddress.createUnresolved("host", 9042)); Session session = Cluster.builder().addContactPointsWithPorts(addresses).build().connect("batch_data"); ResultSet execute = session.execute("SELECT * FROM dnd LIMIT 1"); System.out.println("Result: " + execute.one()); } catch (Exception e) { e.printStackTrace(System.out); } try{ Session session = Cluster.builder().addContactPoint("host").withPort(9042).build().connect("batch_data"); ResultSet execute = session.execute("SELECT * FROM dnd LIMIT 1"); System.out.println("Result: " + execute.one()); } catch (Exception e) { e.printStackTrace(System.out); } {code} Results in the following: {code} com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: host:9042 (com.datastax.driver.core.exceptions.TransportException: [null] Cannot connect)) at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:231) at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:77) at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1382) at com.datastax.driver.core.Cluster.init(Cluster.java:162) at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:333) at com.datastax.driver.core.Cluster.connect(Cluster.java:283) at com.crashlytics.pump.Main.main(Main.java:21) Result: null {code} The first run through results in a NoHostAvailableException and the second run through successfully connects and executes the query (in this case returning no results). These two pieces of code feel like they should do the same thing to me. We are migrating from the old hector client which would take an argument in the form of "hostname[:port],[hostname[:port]...]" and correctly connect to the supplied nodes. With the Cluster builder it looks like the only options are to send in all the hosts as a string and set the port with .withPort() or to pass a collection of InetSocketAddress objects which have both the host and the port specified.

    DataStax JIRA | 10 months ago | Andrew Jorgensen
    com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: host:9042 (com.datastax.driver.core.exceptions.TransportException: [null] Cannot connect))
  3. 0

    Cassandra connection using SSH Tunnel not connecting

    GitHub | 1 month ago | robinson-scott
    org.jkiss.dbeaver.model.exec.DBCException: All host(s) tried for query failed (tried: localhost/127.0.0.1:9042 (com.datastax.driver.core.exceptions.TransportException: [localhost/127.0.0.1] Cannot connect), localhost/0:0:0:0:0:0:0:1:9042 (com.datastax.driver.core.exceptions.TransportException: [localhost/0:0:0:0:0:0:0:1] Cannot connect))
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    NoHostAvailableException in DBeaver when connecting to remote Cassandra docker container

    Stack Overflow | 4 weeks ago | MeanwhileInHell
    org.jkiss.dbeaver.model.exec.DBCException: All host(s) tried for query failed (tried: /192.168.2.2:9042 (com.datastax.driver.core.exceptions.TransportException: [/xx.xx.xx.xx] Cannot connect))
  6. 0

    Does not work with Cassandra 3.0

    GitHub | 11 months ago | gw0
    com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /1.2.3.4:9042 (com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured table schema_keyspaces))

  1. kid 2 times, last 2 weeks ago
24 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. com.datastax.driver.core.exceptions.NoHostAvailableException

    All host(s) tried for query failed (tried: host:9042 (com.datastax.driver.core.exceptions.TransportException: [null] Cannot connect))

    at com.datastax.driver.core.ControlConnection.reconnectInternal()
  2. DataStax Java Driver for Apache Cassandra - Core
    Cluster.connect
    1. com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:231)
    2. com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:77)
    3. com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1382)
    4. com.datastax.driver.core.Cluster.init(Cluster.java:162)
    5. com.datastax.driver.core.Cluster.connectAsync(Cluster.java:333)
    6. com.datastax.driver.core.Cluster.connect(Cluster.java:283)
    6 frames
  3. com.crashlytics.pump
    Main.main
    1. com.crashlytics.pump.Main.main(Main.java:21)
    1 frame