ash42
Databricks Partner

I am seeing the same issue with hikari. When a pooled connection is created then the databricks cluster is terminated (or restarted), the HikariDataSource retains a stale session handle.

Why does connection.isValid() returns true then executing any query on the same connection will fail with invalid sessionHandle. I was expecting the connection.isValid() to return false in this case.

To reproduce:

  1. Create a HikariDataSource referencing a databricks cluster.
  2. Terminate the databricks cluster.
  3. get a connection from the datasource like HikariDataSource.getConnection()
  4. connection.isValid(1) return true.
  5. connection.executeQuery("SELECT 1"), this will block until the cluster is restarted then fail with java.sql.SQLException: [Databricks][JDBCDriver](500051) ERROR processing query/statement. Error Code: 0, SQL state: 08000, Query: SELECT 1, Error message from Server: Invalid SessionHandle.