vertx-sql-client icon indicating copy to clipboard operation
vertx-sql-client copied to clipboard

Bad execution context throw IllegalStateException on `executeBatchAwait()` which do not happen with `executeAwait()` in the same context.

Open ylemoigne opened this issue 5 years ago • 0 comments

Stacktrace

java.lang.IllegalStateException
	at io.vertx.sqlclient.impl.SocketConnectionBase.schedule(SocketConnectionBase.java:130)
	at io.vertx.sqlclient.impl.ConnectionPool$PooledConnection.schedule(ConnectionPool.java:111)
	at io.vertx.sqlclient.impl.Connection.schedule(Connection.java:34)
	at io.vertx.sqlclient.impl.PreparedStatementImpl.batch(PreparedStatementImpl.java:115)
	at io.vertx.sqlclient.impl.PreparedStatementImpl.access$000(PreparedStatementImpl.java:45)
	at io.vertx.sqlclient.impl.PreparedStatementImpl$PreparedStatementQuery.executeBatch(PreparedStatementImpl.java:173)

Version

3.9.0

Context

I won't have a complete reproducer as the full case with coroutines is hard to extract. But I also tried to force context to vertx, and it doesn't solve the issue.

suspend fun createInsertBatch(tx: Transaction, modelId: String, codeHistories: Collection<CodeHistory>) {
// OK
        for (it in codeHistories) {
            tx.prepareAwait(
                //language=PostgreSQL
                """
                INSERT INTO code_history (id, model_id, code_history) VALUES ($1, $2, $3)
                """.trimIndent()
            ).query().executeAwait(
                Tuple.of(
                    it.id, modelId, it.toSQLJsonb()
                )
            )
        }

        // KO
        tx.prepareAwait(
            //language=PostgreSQL
            """
            INSERT INTO code_history (id, model_id, code_history) VALUES ($1, $2, $3)
            """.trimIndent()
        ).query().executeBatchAwait(
            codeHistories.map {
                Tuple.of(
                    it.id, modelId, it.toSQLJsonb()
                )
            }
        )
        
        // Still KO
        withContext(vertx.dispatcher()){
            tx.prepareAwait(
                //language=PostgreSQL
                """
            INSERT INTO code_history (id, model_id, code_history) VALUES ($1, $2, $3)
            """.trimIndent()
            ).query().executeBatchAwait(
                codeHistories.map {
                    Tuple.of(
                        it.id, modelId, it.toSQLJsonb()
                    )
                }
            )
        }
}

Extra

Kotlin 1.3.72

ylemoigne avatar Apr 15 '20 14:04 ylemoigne