Exposed: suspendedTransactionAsync not returning connections to pool

Created on 6 Nov 2019  路  3Comments  路  Source: JetBrains/Exposed

Exposed 0.17.7
Kotlin 1.3.50

The number of queries I can make (with each returning a result before the next is initiated) is equal to the maximum pool size. Then, the process hangs and an exception gets thrown because no connections are available. Regular transactions work fine.

Edit: The suspending function is being called from a ktor "get" block which also uses coroutines. Is this a problem?

// Create data source.
internal val dataSource: HikariDataSource
    get() {
        val config = HikariConfig().apply {
            driverClassName = "org.postgresql.Driver"
            jdbcUrl = System.getenv("JDBC_DATABASE_URL")
            validate()
        }

        return HikariDataSource(config)
    }

// Connect using data source, create table if missing.
fun initdb() {
    Database.connect(dataSource)

    transaction { SchemaUtils.createMissingTablesAndColumns(Spaces) }
}

// Reduce boilerplate.
suspend fun <T> dbquery(block: () -> T): T = suspendedTransactionAsync(Dispatchers.IO) {
    block()
}.await()

// Query (can be executed maximumPoolSize times).
suspend fun readAll() = dbquery { Spaces.selectAll() }
bug waiting for reply

All 3 comments

@ncobc , that's strange as I can see that close should be called on a connection and that means what connection should be returned to a pool.

Could you provide a sample project to test?

We can replicate this, in the particular case of an exception being thrown from the suspended transaction.

Actually... it seems to only affect 0.17.6.

I was creating a test project to replicate the issue and can confirm our problem is present in 0.17.6 and resolved in 0.17.7

I am happy to share the sample project with you I used to confirm the issue - let me know if that would be helpful.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hannesstruss picture hannesstruss  路  5Comments

quangIO picture quangIO  路  5Comments

supertote picture supertote  路  3Comments

coolemza picture coolemza  路  3Comments

mgmeiner picture mgmeiner  路  3Comments