HikariCP determined that the connection was dead, i.e. (connection is evicted or dead)
, and therefore attempted to close it. The driver then said, “Sorry the connection is already closed”, which is not unexpected.
You might think, “Why do you need to close a dead connection?” Well, maybe it was only temporarily unavailable (or slow) so the validation test failed, but the connection is still “alive” from the driver’s perspective. Closing, or at least attempting to, is essential to allow the driver opportunity to cleanup resources.
HikariCP closes connections in five cases:
- The connection failed validation. This is invisible to your application. The connection is retired and replaced. You would see a log message to the effect of
Failed to validate connection....
- A connection was idle for longer than idleTimeout. This is invisible to your application. The connection is retired and replaced. You would see a closure reason of
(connection has passed idleTimeout)
.- A connection reached its maxLifetime. This is invisible to your application. The connection is retired and replaced. You would see a closure reason of
(connection has passed maxLifetime)
, or if the connection is in use at the time of reaching maxLifetime you would see (connection is evicted or dead) at a later time.- The user manually evicted a connection. This is invisible to your application. The connection is retired and replaced. You would see a closure reason of
(connection evicted by user)
.- A JDBC call threw an unrecoverable SQLException. This should be visible to your application. You would see a closure reason of
(connection is broken)
.