From 9e0d9ad644c7cc4d6eb0bd1cde2c771e0bf31887 Mon Sep 17 00:00:00 2001 From: himadieievsv Date: Wed, 2 Oct 2024 15:52:38 +0900 Subject: [PATCH] handle connections that already marked as not allocated --- .../redpulsar/lettuce/abstracts/AbstractLettucePooled.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/redpulsar-lettuce/src/main/kotlin/com/himadieiev/redpulsar/lettuce/abstracts/AbstractLettucePooled.kt b/redpulsar-lettuce/src/main/kotlin/com/himadieiev/redpulsar/lettuce/abstracts/AbstractLettucePooled.kt index e8ecfbb..7d37bc5 100644 --- a/redpulsar-lettuce/src/main/kotlin/com/himadieiev/redpulsar/lettuce/abstracts/AbstractLettucePooled.kt +++ b/redpulsar-lettuce/src/main/kotlin/com/himadieiev/redpulsar/lettuce/abstracts/AbstractLettucePooled.kt @@ -16,6 +16,8 @@ import org.apache.commons.pool2.impl.GenericObjectPool abstract class AbstractLettucePooled>( protected val connectionPool: GenericObjectPool, ) : AutoCloseable, LettuceUnified { + protected val logger = KotlinLogging.logger { } + init { val connection = connectionPool.borrowObject() if (connection !is StatefulRedisConnection<*, *> && connection !is StatefulRedisClusterConnection<*, *>) { @@ -56,11 +58,14 @@ abstract class AbstractLettucePooled>( try { connection.sync().discard() } catch (e: Exception) { - val logger = KotlinLogging.logger { } logger.error(e) { "Could not discard a transaction." } } } - connectionPool.returnObject(connection) + try { + connectionPool.returnObject(connection) + } catch (e: IllegalStateException) { + logger.info { "Failed to return connection to the pool. Skipping error: " + e.message } + } } } }