brettwooldridge / HikariCP

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

Connection failing after about 100 sql queries on the same connection (08S01) - bug #2150

Closed FollowSteph closed 7 months ago

FollowSteph commented 7 months ago

I tried to adjust the configs numerous ways but nothing worked. The only way I was able to resolve the issue was instead of using the same connection over and over (about 100-150 queries) it worked fine. I played with maxLifetime, minimumIdle, idleTimeout, validationTimeout, etc. with no luck. Every value well past the time it took to run the queries by a massive margin (as in it took a few seconds to run).

To replicate specifically the following failed consistently around 100-150 queries (in my case inserts). Yes I should be using batching, and I will, but I was trying to test the individual sql queries to figure out if and where my script had any issues before batching them.

HikariDataSource pool = new HikariDataSource(config)
try (Connection connection = pool.getConnection()) 
{
    sqlQueryList.forEach(sql ->
        SQLUtils.executePreparedStatement(connection, sql);
} catch (Exception e) {
    LOGGER.error(e.getMessage(), e);
}

However this worked consistently:

HikariDataSource pool = new HikariDataSource(config)
sqlQueryList.forEach(sql ->
{
    try (Connection connection = pool.getConnection()) {
        SQLUtils.executePreparedStatement(connection, sql);
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
}

The only difference being the connection is the same in the first whereas the connection is grabbed from the pool each time in the bottom one. I had a max pool size of 3.

** Now here's where it gets really weird. If I set the max pool size to 1 then the initially connection times out after 30 seconds but after that it's able to run all the rest of the sql queries without any issues. I tested up to about 300 queries and it was fine. But it had to time out on the first query before it was able to successfully run.

FollowSteph commented 7 months ago

After a lot of troubleshooting it appears it was an issue on my side. My apologies for the confusion.