From 4aced55317189c815aee650712f849b2c0335474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20P=C3=B6hler?= Date: Mon, 24 Feb 2025 10:44:25 +0100 Subject: [PATCH 1/2] FIX: Try to establish new connection when dataSource is down --- .../java/io/ebean/datasource/pool/PooledConnectionQueue.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ebean-datasource/src/main/java/io/ebean/datasource/pool/PooledConnectionQueue.java b/ebean-datasource/src/main/java/io/ebean/datasource/pool/PooledConnectionQueue.java index e999ce2..71a4cac 100644 --- a/ebean-datasource/src/main/java/io/ebean/datasource/pool/PooledConnectionQueue.java +++ b/ebean-datasource/src/main/java/io/ebean/datasource/pool/PooledConnectionQueue.java @@ -225,7 +225,10 @@ private PooledConnection _obtainConnection() throws InterruptedException, SQLExc // or SQLException but that is ok as its only an indicator hitCount++; // are other threads already waiting? (they get priority) - if (waitingThreads == 0) { + if (waitingThreads == 0 + // If datasource is down, we might run into _obtainConnectionWaitLoop forever (or until no thread requests connections), + // in case all connections were busy on reset(). Without this, it would be hard to recover/reconnect the pool + || !pool.isDataSourceUp()) { PooledConnection freeConnection = extractFromFreeList(); if (freeConnection != null) { return freeConnection; From 08c971c479c0fbee933e9b879dca03f744279ac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20P=C3=B6hler?= Date: Tue, 25 Feb 2025 09:34:31 +0100 Subject: [PATCH 2/2] Better fix --- .../java/io/ebean/datasource/pool/PooledConnectionQueue.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ebean-datasource/src/main/java/io/ebean/datasource/pool/PooledConnectionQueue.java b/ebean-datasource/src/main/java/io/ebean/datasource/pool/PooledConnectionQueue.java index 71a4cac..20280b4 100644 --- a/ebean-datasource/src/main/java/io/ebean/datasource/pool/PooledConnectionQueue.java +++ b/ebean-datasource/src/main/java/io/ebean/datasource/pool/PooledConnectionQueue.java @@ -227,8 +227,8 @@ private PooledConnection _obtainConnection() throws InterruptedException, SQLExc // are other threads already waiting? (they get priority) if (waitingThreads == 0 // If datasource is down, we might run into _obtainConnectionWaitLoop forever (or until no thread requests connections), - // in case all connections were busy on reset(). Without this, it would be hard to recover/reconnect the pool - || !pool.isDataSourceUp()) { + // in case threads were waiting when reset() occurs. Without this, it would be hard to recover/reconnect the pool. + || busyList.size() < maxSize) { PooledConnection freeConnection = extractFromFreeList(); if (freeConnection != null) { return freeConnection;