Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

Erick Ramirez avatar image
Erick Ramirez asked ·

Getting "no response to connection startup within timeout" using the gocql driver on Astra

A developer reported issues connecting to DataStax Astra with the gocql driver using the sample code in How to connect to Astra with the gocql driver.

When running the sample code as-is, the output is:

$ ./astra_gocql_connect 
According to independent.co.uk, the top 5 most liveable cities in 2019 were:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x148 pc=0x66f8d7]

goroutine 1 [running]:
github.com/gocql/gocql.(*Query).defaultsFromSession(0xc000108120)
/home/ubuntu/go/src/github.com/gocql/gocql/session.go:842 +0x37
github.com/gocql/gocql.(*Session).Query(0x0, 0x706528, 0x58, 0x0, 0x0, 0x0, 0x0)
/home/ubuntu/go/src/github.com/gocql/gocql/session.go:383 +0xb2
main.main()
/home/ubuntu/astra_gocql_connect.go:48 +0x6dc

With some error handling added when creating the session:

    session, err := _cluster.CreateSession()
    if err != nil {
        panic(err)
    }

the output looks like:

$ ./astra_gocql_connect 
panic: gocql: unable to create session: unable to discover protocol version: gocql: no response to connection startup within timeout

goroutine 1 [running]:
main.main()
/home/ubuntu/astra_gocql_connect.go:43 +0x9e7
astragocql
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered ·

The connection to the Astra database times out when the driver is configured to connect to the wrong port, for example the generic port in the config.json file instead of the CQL port:

{
  "host": "362f3f09-c535-443c-ac2b-24460ed92e4f-us-east1.db.astra.datastax.com",
  "port": 30373,
  "cql_port": 32449,
  "keyspace": "community",
  ...
}

As I stated in my instructions, you need to use the CQL port specified in the cqlshrc file that is included in the secure connect bundle of your database. For example:

[connection]
hostname = 362f3f09-c535-443c-ac2b-24460ed92e4f-us-east1.db.astra.datastax.com
port = 32449
ssl = true

Using the example above, port 30373 is a metadata port used for admin purposes. This port is not listening for CQL requests so the driver never gets the appropriate native protocol acknowledgement on this port and the connection attempt eventually times out.

The correct port to use for client connections is the CQL port 32449. Using this port, we get the expected results from the sample code:

$ ./astra_gocql_connect 
According to independent.co.uk, the top 5 most liveable cities in 2019 were:
        Rank 1: Vienna, Austria
        Rank 2: Melbourne, Australia
        Rank 3: Sydney, Australia
        Rank 4: Osaka, Japan
        Rank 5: Calgary, Canada

Cheers!

Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.