Can you tell me what database and driver you are using?
There are
two code paths for checking the aliveness of the connection. If the driver supports the JDBC 4.0 Connection.
isValid(timeout) method, we're going to use that. However, many drivers do not implement this with a socket level timeout, which can cause the issue that you are seeing.
If you look in the code linked above, you'll see the second connection test path, which is run if a connectionTestQuery is configured (isUseJdbcValidation will be false in that case). In this case, we try to bracket the test query execution by setting the network timeout on the connection. That is, if the driver supports the Connection.setNetworkTimeout() API, it will be set.
If the driver does not support setting the network timeout, there won't be a lot that we can do to return back from a validation within the timeout when there is a network disruption.
So, I would first suggest configuring the pool to use a connectionTestQuery, and see if that clears things up. If you turn on debug logging you can see messages during startup like:
Connection.setNetworkTimeout() is not supported
If you do see that message, there is nothing HikariCP can do to return within the connectionTimeout in the case of a network disruption. If you don't see that message, it implies that it is supported, and should work.