Skip to content

NewSession sometimes panics when it should return an error #1370

@miroswan

Description

@miroswan

Please answer these questions before submitting your issue. Thanks!

What version of Cassandra are you using?

3.0.9

What version of Gocql are you using?

v0.0.0-20190810123941-df4b9cc33030

What did you do?

gocql.NewSession panics when cassandra has not yet reported that it can receive connections

panic: no valid connect address for host: [HostInfo hostname="0.0.0.0" connectAddress="0.0.0.0" peer="<nil>" rpc_address="<nil>" broadcast_address="<nil>" preferred_ip="<nil>" connect_addr="0.0.0.0" connect_addr_source="invalid" port=9042 data_centre="" rack="" host_id="" version="v0.0.0" state=UP num_tokens=0]. Is your cluster configured correctly?

What did you expect to see?

I expect an error to be returned instead of a panic. This is where things seem to be breaking down:

https://github.com/gocql/gocql/blob/2274c8a9fab68a2be1c558b32eab48cb853163aa/session.go#L221

The ConnectAddress method does not return an error on failure. It panics. If this method returned an error in this condition, we could check for it here and bubble it up. This would allow me to keep checking until Cassandra is up instead of the thread crashing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions