JdbcLockRegistry not able to recover from JpaSystemException that wraps SQLException with Postgres 40001 SQLState #3613
Labels
status: invalid
Not reproducable or not relevant to the current state of the project
I was trying to implement LockRegistryLeaderInitiator with the ability to use one table and using 2 or more regions in it.
The project is implemented using Spring Data Jpa and Postgres 13. When I run the application with this configuration sometimes I get JpaSystemException with inner TransactionException (org.hibernate.TransactionException: Unable to commit against JDBC Connection). The cause inside is PSQLException with SQLStata=40001
The problem is that Spring JPA does not wrap this exception with any ConcurrencyFailureException. The problem is well known and maybe one day will be fixed. The problem and workaround is highlighted here: https://stackoverflow.com/questions/59006479/how-to-retry-a-postgresql-serializable-transaction-with-spring
To reproduce this problem create JPA based application + use Postgres 13.2, create 2 JdbcLockRegistries, 2 DefaultLockRepositories and 2 LockRegistryLeaderInitiators, for example like this:
Create an event listener in the application like this:
After that, if you run this application very soon you will see the problem. The leadership will be granted and revoked from time to time because the exception described above is not handled properly.
One of the workarounds for this problem is to override JpaTransactionManager and handle this exception manually:
The text was updated successfully, but these errors were encountered: