Skip to content

Commit

Permalink
handle connections that already marked as not allocated
Browse files Browse the repository at this point in the history
  • Loading branch information
himadieievsv committed Oct 2, 2024
1 parent 74bdefe commit 9e0d9ad
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import org.apache.commons.pool2.impl.GenericObjectPool
abstract class AbstractLettucePooled<K, V, T : StatefulConnection<K, V>>(
protected val connectionPool: GenericObjectPool<T>,
) : AutoCloseable, LettuceUnified<K, V> {
protected val logger = KotlinLogging.logger { }

init {
val connection = connectionPool.borrowObject()
if (connection !is StatefulRedisConnection<*, *> && connection !is StatefulRedisClusterConnection<*, *>) {
Expand Down Expand Up @@ -56,11 +58,14 @@ abstract class AbstractLettucePooled<K, V, T : StatefulConnection<K, V>>(
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 }
}
}
}
}

0 comments on commit 9e0d9ad

Please sign in to comment.