Skip to content

Nightmare bug when using transaction on r2dbc #413

Closed

Description

@knuclechan

Library

jasync-r2dbc-mysql-2.2.3

Issue

  1. When opening transaction, it sets autocommit = 0 and runs START TRANSACTION, which is meaningless duplicate
  2. When commit or rollback a transaction it does not set the autocomit back to 1, which causing the statement afterward being in a transaction!!!!!!!!!

圖片

override fun beginTransaction(): Publisher<Void> {
        return executeVoid("START TRANSACTION")
    }

    override fun beginTransaction(definition: TransactionDefinition): Publisher<Void> {
        return Mono.defer {
            val setAutoCommit = Mono.from(setAutoCommit(false))

            val setLockWaitTimeout = Mono.justOrEmpty(definition.getAttribute(TransactionDefinition.LOCK_WAIT_TIMEOUT))
                .flatMap { timeout -> Mono.from(setLockWaitTimeout(timeout)) }

            val changeIsolationLevel = Mono.justOrEmpty(definition.getAttribute(TransactionDefinition.ISOLATION_LEVEL))
                .flatMap { newIsolationLevel -> Mono.from(setTransactionIsolationLevel(newIsolationLevel)) }

            val startTransaction = Mono.from(beginTransaction())

            return@defer Mono.from(setAutoCommit)
                .then(setLockWaitTimeout)
                .then(changeIsolationLevel)
                .then(startTransaction)
                .then()
        }
    }

    override fun commitTransaction(): Publisher<Void> {
        return executeVoid("COMMIT")
    }

    override fun rollbackTransaction(): Publisher<Void> {
        return executeVoidAfterCurrent("ROLLBACK")
    }

Solution

Remove val setAutoCommit = Mono.from(setAutoCommit(false)) at JasyncClientConnection.kt

Activity

  1. oshai commented on Aug 30, 2023

    @oshai
    Contributor

    Thanks for reporting! Would you like to create a PR for the fix?

  2. oshai commented on Sep 4, 2023

    @oshai
    Contributor

    Fixed in 2.2.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions