maxmello
10/24/2019, 9:18 AMval dao = newSuspendedTransaction { MyDAO.findByValueOrThrowException(value) }
// MyDAO companion (LongEntityClass)
suspend fun findByValueOrThrowException(value: String): MyDAO {
return withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
find { MyTable.value eq value }.firstOrNull() ?: throw RuntimeException("MyDAO not found")
}
}
10 seconds after the exception is thrown, I get the following log message: com.zaxxer.hikari.pool.ProxyLeakTask - Connection leak detection triggered for org.postgresql.jdbc.PgConnection@5b4d25e7 on thread DefaultDispatcher-worker-1, stack trace follows: java.lang.Exception: Apparent connection leak detected
As you can see, I am using Hikari for a thread pool (config.leakDetectionThreshold = 10000L, corresponding to the 10 seconds after the message appears)
So am I not allowed to throw an exception and catch it outside the transaction context, or am I doing something else wrong? (I am using Postgres)spand
10/24/2019, 9:23 AMnewSuspendedTransaction
yet but why do you change context ?maxmello
10/24/2019, 9:26 AMspand
10/24/2019, 9:27 AMmaxmello
10/24/2019, 9:48 AMEvan R.
10/24/2019, 12:53 PMspand
10/24/2019, 12:56 PMval myDAO = newSuspendedTransaction { find { MyTable.value eq value }.firstOrNull() } ?: throw RuntimeException()
Evan R.
10/24/2019, 12:58 PMspand
10/24/2019, 1:16 PMEvan R.
10/24/2019, 1:45 PM