From 93c71780125bcd499af1faa652c2a524d6217f7c Mon Sep 17 00:00:00 2001 From: Brett Wooldridge Date: Thu, 9 Jan 2020 23:59:47 +0900 Subject: [PATCH] Fixes #1528 regression in fail fast handling. --- .../com/zaxxer/hikari/pool/HikariPool.java | 20 ++++++------------- .../java/com/zaxxer/hikari/pool/PoolBase.java | 4 ++++ 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/zaxxer/hikari/pool/HikariPool.java b/src/main/java/com/zaxxer/hikari/pool/HikariPool.java index dc462a73..e5018114 100644 --- a/src/main/java/com/zaxxer/hikari/pool/HikariPool.java +++ b/src/main/java/com/zaxxer/hikari/pool/HikariPool.java @@ -127,9 +127,9 @@ public final class HikariPool extends PoolBase implements HikariPoolMXBean, IBag ThreadFactory threadFactory = config.getThreadFactory(); - LinkedBlockingQueue addQueue = new LinkedBlockingQueue<>(config.getMaximumPoolSize()); - this.addConnectionQueue = unmodifiableCollection(addQueue); - this.addConnectionExecutor = createThreadPoolExecutor(addQueue, poolName + " connection adder", threadFactory, new ThreadPoolExecutor.DiscardPolicy()); + LinkedBlockingQueue addConnectionQueue = new LinkedBlockingQueue<>(config.getMaximumPoolSize()); + this.addConnectionQueue = unmodifiableCollection(addConnectionQueue); + this.addConnectionExecutor = createThreadPoolExecutor(addConnectionQueue, poolName + " connection adder", threadFactory, new ThreadPoolExecutor.DiscardPolicy()); this.closeConnectionExecutor = createThreadPoolExecutor(config.getMaximumPoolSize(), poolName + " connection closer", threadFactory, new ThreadPoolExecutor.CallerRunsPolicy()); this.leakTaskFactory = new ProxyLeakTaskFactory(config.getLeakDetectionThreshold(), houseKeepingExecutorService); @@ -493,22 +493,14 @@ public final class HikariPool extends PoolBase implements HikariPoolMXBean, IBag logger.error("{} - Error thrown while acquiring connection from data source", poolName, e.getCause()); lastConnectionFailure.set(e); } - return null; - } - catch (SQLException e) { - if (poolState == POOL_NORMAL) { // we check POOL_NORMAL to avoid a flood of messages if shutdown() is running concurrently - logger.debug("{} - Cannot acquire connection from data source", poolName, e); - lastConnectionFailure.set(new ConnectionSetupException(e)); - } - return null; } catch (Exception e) { if (poolState == POOL_NORMAL) { // we check POOL_NORMAL to avoid a flood of messages if shutdown() is running concurrently - logger.error("{} - Error thrown while acquiring connection from data source", poolName, e); - lastConnectionFailure.set(new ConnectionSetupException(e)); + logger.debug("{} - Cannot acquire connection from data source", poolName, e); } - return null; } + + return null; } /** diff --git a/src/main/java/com/zaxxer/hikari/pool/PoolBase.java b/src/main/java/com/zaxxer/hikari/pool/PoolBase.java index 1356a4ee..631d8a2a 100644 --- a/src/main/java/com/zaxxer/hikari/pool/PoolBase.java +++ b/src/main/java/com/zaxxer/hikari/pool/PoolBase.java @@ -34,6 +34,7 @@ import javax.sql.DataSource; import java.lang.management.ManagementFactory; import java.sql.Connection; import java.sql.SQLException; +import java.sql.SQLTransientConnectionException; import java.sql.Statement; import java.util.Properties; import java.util.concurrent.Executor; @@ -351,6 +352,9 @@ abstract class PoolBase String password = config.getPassword(); connection = (username == null) ? dataSource.getConnection() : dataSource.getConnection(username, password); + if (connection == null) { + throw new SQLTransientConnectionException("DataSource returned null unexpectedly"); + } setupConnection(connection); lastConnectionFailure.set(null);