edgedb-java icon indicating copy to clipboard operation
edgedb-java copied to clipboard

Transaction stuck after first step execution

Open timemanx opened this issue 1 year ago • 3 comments

Hi,

I'm using the transaction API but it seems the transaction always gets stuck after executing the first step. I'm using EdgeDB 5.6 on EdgeDB Cloud and Java client library version 0.3.0.

Here is a simple example using Kotlin.

package com.test.edgedbclient

import com.edgedb.driver.EdgeDBClient
import com.edgedb.driver.EdgeDBConnection
import kotlinx.coroutines.future.await

suspend fun main() {
    val client = EdgeDBClient(EdgeDBConnection.parse(null, null, true))
    val output = client.transaction { tx ->
        tx.query(String::class.java, "SELECT 'Hello, World 1!'")
            .thenCompose {
                println("Output0: $it")
                tx.query(String::class.java, "SELECT 'Hello, World 2!'")
            }
            .thenCompose {
                println("Output1: $it")
                tx.query(String::class.java, "SELECT 'Hello, World 3!'")
            }
    }.await()

    println("--- Completed ---")
    println("Final output: $output")
    client.close()
}

The output is Output0: [Hello, World 1!] from the first step and then it's stuck.

I believe this is happening due to the semaphore in TransactionImpl being acquired https://github.com/edgedb/edgedb-java/blob/3ddbee1455ad0216d96346ceb71e34ec158bc88f/src/driver/src/main/java/com/edgedb/driver/internal/TransactionImpl.java#L98-L114 but never being released in the executeTransactionStep method after completion of the step. https://github.com/edgedb/edgedb-java/blob/3ddbee1455ad0216d96346ceb71e34ec158bc88f/src/driver/src/main/java/com/edgedb/driver/internal/TransactionImpl.java#L71-L96

This issue could be the same as https://github.com/edgedb/edgedb-java/issues/21.

Please let me know if any other details are required.

Thanks

timemanx avatar Dec 15 '24 03:12 timemanx

I can get it to work by calling semaphore.release() in whenComplete().

-).thenCompose(v -> v);
+)
+.thenCompose(v -> v)
+.whenComplete((result, error) -> {
+    semaphore.release();  // Release in both success and failure cases
+});

on this line https://github.com/edgedb/edgedb-java/blob/3ddbee1455ad0216d96346ceb71e34ec158bc88f/src/driver/src/main/java/com/edgedb/driver/internal/TransactionImpl.java#L95

Not sure whether it can cause any side-effects though.

timemanx avatar Dec 15 '24 04:12 timemanx

@quinchs Any possibility of a fix soon?

timemanx avatar Dec 18 '24 10:12 timemanx

Facing same issue, by when it can be fixed?

KageRiyuu avatar Dec 20 '24 04:12 KageRiyuu