Skip to content

JdbcLockRegistry should retry on DeadlockLoserDataAccessException  #2467

Closed
@brempusz

Description

@brempusz

I am using LockRegistryLeaderInitiator with JdbcLockRegistry. It worked fine on 5.6.36 but after the migration to 5.7.19 I noticed flood of "leader granted/revoked" events when more than on instance of my service is running. After some debugging I noticed it is caused by DeadlockLoserDataAccessException not handled as "retry" in JdbcLockRegistry.

MySql 5.7.15 introduced setting innodb_deadlock_detect (enabled by default, see https://dev.mysql.com/doc/refman/5.7/en/innodb-parameters.html#sysvar_innodb_deadlock_detect).

When this setting is enabled exception will be thrown from MySql JDBC driver when deadlock is detected while accessing table row (vendorCode=1213, SQLState=40001, message: Deadlock found when trying to get lock; try restarting transaction). It is then wrapped to spring exception DeadlockLoserDataAccessException.

JdbcLockRegistry does not handle DeadlockLoserDataAccessException with "try again" action (as it does for CannotSerializeTransactionException, TransactionTimedOutException, QueryTimeoutException).

see

catch (CannotSerializeTransactionException e) {
// try again
}
catch (TransactionTimedOutException e) {
// try again
}
catch (QueryTimeoutException e) {
// try again
}
catch (Exception e) {
this.delegate.unlock();
rethrowAsLockException(e);
}

Spring Boot 1.5.13.RELEASE
Spring Integration JDBC 4.3.16.RELEASE
MySQL 5.6.36/5.7.19

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