From 4ae55c90c8860dd3824366cb34f49d3cb4c915ac Mon Sep 17 00:00:00 2001 From: Brett Wooldridge Date: Tue, 18 Apr 2017 01:08:55 +0900 Subject: [PATCH] Comment #867 Support network timeout even for Connection.isValid(). --- src/main/java/com/zaxxer/hikari/pool/PoolBase.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/zaxxer/hikari/pool/PoolBase.java b/src/main/java/com/zaxxer/hikari/pool/PoolBase.java index 77efb61aa..61bd746be 100755 --- a/src/main/java/com/zaxxer/hikari/pool/PoolBase.java +++ b/src/main/java/com/zaxxer/hikari/pool/PoolBase.java @@ -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) {