JDBC: GetConnection hangs on unavailable cluster

Hi all!

I am just starting to look into cockroachDB. I have set up an insecure three node cluster using docker. (replication factor=3)

Furthermore I have a java test client that repeats the following steps a defined number of times:
get a connection -> execute a select -> close the connection

The following situations occured:
a. As expected: When two or three nodes are online it works without problems.
b. As expected: When all nodes are stopped I get a error message when trying to connect.
c. Now I would expect to get an error when only one node is available as well because the cluster is unavailable. But instead DriverManager.getConnection(DB_URL, props) hangs indefinetely.

Is there any way to configure cockroachDB to return an sqlerror or something similar?

Best regards,
Steffen

I guess https://jdbc.postgresql.org/documentation/head/connect.html a connectTimeout would do what you need?

1 Like

Thanks a lot for your reply! I had the same idea and couldn’t get it to work. Now I have tried it again and it ended up being “loginTimeout” instead of “connectTimeout”. I would still be interested whether something similar could also be done via cockroachDB configuration.

Hi Steffen,

I don’t think we have a way to do what you’re describing, I think the default behaviour is that we wait in the hopes of the cluster becoming available again. Having this alternative behaviour sounds like a useful feature though - I’ve opened https://github.com/cockroachdb/cockroach/issues/29515 to track it, please comment there if you have any other feedback on this!

Justin

1 Like