Skip to content

Bug on setting isolation level on r2dbc-mysql #409

Closed

Description

@knuclechan

I've set the transaction isolation level to read commited at postAllocate for the connection.

private Publisher<Void> initIsolationLevel(Connection conn){
		if(conn.getTransactionIsolationLevel() != IsolationLevel.READ_COMMITTED) {
			return conn.setTransactionIsolationLevel(IsolationLevel.READ_COMMITTED);
		}
		return Mono.empty();
	}

According to the documentation, this should be across the lifetime of the connection. But turn out it is not true, the isolation level switch back to repeatable read immediately after the first transaction is run.
This is observed by using select * from performance_schema.events_transactions_current

I look into the source code. On the r2dbc-mysql project,

override fun setTransactionIsolationLevel(isolationLevel: IsolationLevel): Publisher<Void> {
        return executeVoidAfterCurrent("SET TRANSACTION ISOLATION LEVEL ${isolationLevel.asSql()}")
            .doOnSuccess { this.isolationLevel = isolationLevel }
    }

The statement to set the isolation level is not correct. The session keyword should be added to make it effective to all the subsequent transactions. (ref: https://dev.mysql.com/doc/refman/8.0/en/set-transaction.html)
SET SESSION TRANSACTION ISOLATION LEVEL ${isolationLevel.asSql()}

This bug is still there at the master source code
https://github.com/jasync-sql/jasync-sql/blob/master/r2dbc-mysql/src/main/java/JasyncClientConnection.kt

The bug may be also true for other sub-project as well

Activity

  1. oshai commented on Jul 31, 2023

    @oshai
    Contributor

    Would you like to create a PR to fix it?

  2. oshai commented on Aug 14, 2023

    @oshai
    Contributor

    Fix in 2.2.3.

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