Search code examples
spring-bootmariadbhikaricp

Hikari connection is not getting timed out


I Have the following Hikari configuration in my spring boot app. Queries are taking more than the connection-timeout time set. However, timeout never happened. I am keeping as low as possible to simulate the connection timeout.

    HikariConfig dataSourceConfig = new HikariConfig();
    dataSourceConfig.setDriverClassName(config.driver);
    dataSourceConfig.setJdbcUrl(config.url);
    dataSourceConfig.setUsername(config.user);
    dataSourceConfig.setPassword(config.password);
    dataSourceConfig.setConnectionTestQuery(config.validationQuery);
    dataSourceConfig.setMaximumPoolSize(config.poolMax);
    dataSourceConfig.setConnectionTimeout(300);
    dataSourceConfig.setIdleTimeout(10000);
    dataSourceConfig.setMaxLifetime(60000);
    JdbcTemplate jdbcTemplate = new JdbcTemplate(new HikariDataSource(dataSourceConfig));

Here is some log that shows the query ran for more than 300ms.

Time elapsed to run query......2913

Using Hikari 3.2 and mariadb

Thanks.


Solution

  • From: https://github.com/brettwooldridge/HikariCP

    connectionTimeout This property controls the maximum number of milliseconds that a client (that's you) will wait for a connection from the pool. If this time is exceeded without a connection becoming available, a SQLException will be thrown. Lowest acceptable connection timeout is 250 ms. Default: 30000 (30 seconds)

    So this property is more about how long your application will wait for a connection, not how long a query is allowed to execute.

    I think what you want is "max_statement_time": https://mariadb.com/kb/en/library/server-system-variables/#max_statement_time

    Maximum time in seconds that a query can execute before being aborted. This includes all queries, not just SELECT statements, but excludes statements in stored procedures. If set to 0, no limit is applied.