Deadlock Issues while Realm Deletion

Hi Experts,

I am facing an issue where some realms fail to delete while running tests which are combination of multiple realm creation and deletion.
We are using Keycloak-4.7.0-final running in clustered mode. If someone already have came across this issue can suggest any best practises to follow or bad practise to avoid to take care this issue.

2020-07-28 00:19:51,691 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-103) Deadlock found when trying to get lock; try restarting transaction
2020-07-28 00:19:51,692 ERROR [] (default task-103) Uncaught server error: javax.persistence.OptimisticLockException: org.hibernate.exception.LockAcquisitionException: could not execute statement
at org.hibernate.internal.ExceptionConverterImpl.wrapLockException(
at org.hibernate.internal.ExceptionConverterImpl.convert(
at org.hibernate.internal.ExceptionConverterImpl.convert(
at org.hibernate.query.internal.AbstractProducedQuery.executeUpdate(
at org.keycloak.models.jpa.JpaUserProvider.preRemove(
at org.keycloak.models.cache.infinispan.UserCacheSession.preRemove(
at org.keycloak.models.jpa.JpaRealmProvider.removeRealm(
at org.keycloak.models.cache.infinispan.RealmCacheSession.removeRealm(


Try upgrading first?
Have you checked all fixed issues since that version?
This could be a non issue to start with.

as i understand, this could be because when delete happens a many index in mysql needs to be adjusted, and possibly row locks may be causing the dead locks.

In general, does the transaction reaper in keycloak do a retry? is there any way to configure the wildfly to retry these?

A deadlock is a concurrency problem, 2 transactions try to access the same data at the same time. Both are waiting for each other.
This seems like a straightforward bug, that’s why I proposed to upgrade first or check the fixed issues since your version.
With Keycloak upgrades comes also Wildfly updates.