brettwooldridge / HikariCP

光 HikariCP・A solid, high-performance, JDBC connection pool at last.
Apache License 2.0
19.91k stars 2.92k forks source link

getConnection Method is not throwing exception even when the key is expired #2176

Open dsinghal-nice opened 7 months ago

dsinghal-nice commented 7 months ago

I have a use case where I am using HikariCP for connecting with my Snowflake database using private key. I have initialized my pool when my microservice starts, but we have a policy of private key rotation after a few days. In Snowflake last 2 private keys are stored, which allows the connection to work with old key as well. But when the rotation happens more than 2 times, the Hikari connection should start throwing error which is not happening currently, it still gets the connection and executes the query.

if (hikariDataSource == null) {
            final Properties properties = snowflakeDatasourceConfig.getSnowflakeProperties();
            var hikariConfig = generateHikariConfig(snowflakeDatasourceConfig, properties);
            hikariDataSource = new HikariDataSource(hikariConfig);
        }

I am preparing my DataSource at the beginning of the server start and then using hikariDataSource.getConnection() method every time when I need a new connection for a query to be executed in Snowflake. Ideally the getConnection() method should throw Exception, but it is not.

dsinghal-nice commented 7 months ago

Can someone please help me understand, why getConnection() method is not throwing SQLTransientException as soon as the key is rotated in AWS or the old key is expired (in a simpler way). Hikari CP throws exception after a certain amount of time.

12:28:29.558 [dev] [2.93] [] [] [HikariPool-4 connection adder] ERROR n.s.clie.jdbc.SnowflakeBasicDataSource [] [] [] [] [] Failed to create a connection for {{username}} at jdbc:snowflake://{{account}}.{{private_link}}?allowUnderscoresInHost=true: net.snowflake.client.jdbc.SnowflakeSQLException: !394304!
12:28:29.773 [dev] [2.93] [] [] [http-nio-9090-exec-2] INFO c.n.s.w.q.a.service.QueryEngineServiceImpl [] [] [] [] [] start sfQueryToExecute
12:28:29.887 [dev] [2.93] [] [] [http-nio-9090-exec-2] INFO c.n.s.w.q.a.s.snowfl.SnowflakeQueryExecutor [] [] [] [] [] Query Trace ID: 4e666969c3f455d7, Query Id: 01b2c32c-0904-5fa1-0009-4b8317312322
12:28:29.887 [dev] [2.93] [] [] [http-nio-9090-exec-2] INFO c.n.s.w.q.a.service.QueryEngineServiceImpl [] [] [] [] [] end sfQueryToExecute

As you can see, I am getting error from HikariPool-4 connection adder, but Hikari Pool is still letting me use the connections.