Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using forUpdate in suspended transaction causes deadlock #2411

Open
satamas opened this issue Feb 18, 2025 · 0 comments
Open

Using forUpdate in suspended transaction causes deadlock #2411

satamas opened this issue Feb 18, 2025 · 0 comments

Comments

@satamas
Copy link

satamas commented Feb 18, 2025

Reproducer:

fun main(args: Array<String>) {
    Database.connect(
        "jdbc:postgresql://localhost:54321/grazie",
        user = "admin",
        password = "admin",
        driver = "org.postgresql.Driver"
    )
    while (true) {
        try {
            runBlocking {
                repeat(2) {
                    launch {
                        newSuspendedTransaction {
                            val license = UserLicenseEntity.find { UserLicenseTable.id eq 1 }.forUpdate().singleOrNull()
                            println(license?.licenseType ?: "No license found")
                            delay(50)
                        }
                    }
                }
            }
        } catch (e: Exception) {
        }
    }
}

class UserLicenseEntity(id: EntityID<Int>) : IntEntity(id) {
    val licenseType by UserLicenseTable.license_type

    companion object : IntEntityClass<UserLicenseEntity>(UserLicenseTable)
}

object UserLicenseTable : IntIdTable("user_license") {
    val license_type = text("license_type")
}

If I am not missing something, it should run endless and print licenseType. Instead, licenseType is printed once and then the program hangs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant