brettwooldridge / HikariCP

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

isConnectionDead logs warnings when the connection should simply be closed #2210

Closed bh-tt closed 1 week ago

bh-tt commented 1 week ago

We recently encountered an increased number of warnings from hikari, all about failing to validate a connection before borrowing it from the pool. The log line in question is HikariPool-2 - Failed to validate connection org.mariadb.jdbc.Connection@294613b0 ((conn=55230) Connection.setNetworkTimeout cannot be called on a closed connection). Possibly consider using a shorter maxLifetime value.

This appears to come from Poolbase.isConnectionDead, which does 2 setNetworkTimeout calls (both before validation to the validationTimeout and afterward to reset the network timeout back to what it was). If the connection was closed due to errors (at least for the mariadb 3.x driver) the setNetworkTimeout call itself results in an SQLException, which is then logged as a warning. The result is a large number (thousands/day) of warnings about the connection being closed from a method that is supposed to determine whether the connection is closed.

This method should not log warnings (maybe info or debug?) when a return value of false is an expected result (e.g. the connection should not be used, evict it).

I think there are 2 ways to fix this:

bh-tt commented 1 week ago

Well we found the underlying error: very high system load, likely causing network issues. I'll close this.