Skip to content

Commit

Permalink
Comment brettwooldridge#867 Support network timeout even for Connecti…
Browse files Browse the repository at this point in the history
…on.isValid().
  • Loading branch information
brettwooldridge authored and kollstrom committed Feb 4, 2021
1 parent 5d190f4 commit 4ae55c9
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/main/java/com/zaxxer/hikari/pool/PoolBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,28 +143,30 @@ boolean isConnectionAlive(final Connection connection)
{
try {
try {
setNetworkTimeout(connection, validationTimeout);

final long validationSeconds = (int) Math.max(1000L, validationTimeout) / 1000;

if (isUseJdbc4Validation) {
return connection.isValid((int) MILLISECONDS.toSeconds(Math.max(1000L, validationTimeout)));
return connection.isValid((int) validationSeconds);
}

setNetworkTimeout(connection, validationTimeout);

try (Statement statement = connection.createStatement()) {
if (isNetworkTimeoutSupported != TRUE) {
setQueryTimeout(statement, (int) MILLISECONDS.toSeconds(Math.max(1000L, validationTimeout)));
setQueryTimeout(statement, (int) validationSeconds);
}

statement.execute(config.getConnectionTestQuery());
}
}
finally {
setNetworkTimeout(connection, networkTimeout);

if (isIsolateInternalQueries && !isAutoCommit) {
connection.rollback();
}
}

setNetworkTimeout(connection, networkTimeout);

return true;
}
catch (Exception e) {
Expand Down

0 comments on commit 4ae55c9

Please sign in to comment.