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 } + } } } }