Duplicate exception with use of offline tokens and mysql

Hey,

we are in test fase of using offline sessions on a kubernetes environment (2 pods) and with mysql.
We have keycloak version 10.0.2.

For the first time after restart of the kubernetes system we got a duplicate exception, is this a bug i have to report or is it an configuration issue ??

Hope anyone can give advice

2020-11-16 10:55:10,777 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-1) SQL Error: 1062, SQLState: 23000

2020-11-16 10:55:10,777 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-1) Duplicate entry ‘4724c969-25fa-4ce7-8fbf-5d9287d40782-ab0218b1-990b-447b-85ae-4c7’ for key ‘PRIMARY’

2020-11-16 10:55:10,778 ERROR [org.keycloak.services.error.KeycloakErrorHandler] (default task-1) Uncaught server error: org.keycloak.models.ModelDuplicateException: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not execute statement

at org.keycloak.keycloak-model-jpa@10.0.2//org.keycloak.connections.jpa.PersistenceExceptionConverter.convert(PersistenceExceptionConverter.java:57)

at org.keycloak.keycloak-model-jpa@10.0.2//org.keycloak.connections.jpa.PersistenceExceptionConverter.invoke(PersistenceExceptionConverter.java:51)

at javax.persistence.api@2.2.3//com.sun.proxy.$Proxy122.flush(Unknown Source)

at org.keycloak.keycloak-model-jpa@10.0.2//org.keycloak.models.jpa.session.JpaUserSessionPersisterProvider.createClientSession(JpaUserSessionPersisterProvider.java:107)

at org.keycloak.keycloak-services@10.0.2//org.keycloak.services.managers.UserSessionManager.createOfflineClientSession(UserSessionManager.java:154)

at org.keycloak.keycloak-services@10.0.2//org.keycloak.services.managers.UserSessionManager.createOrUpdateOfflineSession(UserSessionManager.java:69)

at org.keycloak.keycloak-services@10.0.2//org.keycloak.protocol.oidc.TokenManager$AccessTokenResponseBuilder.generateRefreshToken(TokenManager.java:782)

at org.keycloak.keycloak-services@10.0.2//org.keycloak.protocol.oidc.endpoints.TokenEndpoint.codeToToken(TokenEndpoint.java:401)

at org.keycloak.keycloak-services@10.0.2//org.keycloak.protocol.oidc.endpoints.TokenEndpoint.processGrantRequest(TokenEndpoint.java:187)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.base/java.lang.reflect.Method.invoke(Method.java:566)

hey,

we found the above issue ourselfs. after debugging it shows that our distributed caches returns null on check for offline usersession, while it does exist in database. And therefore decides to do a insert. We even have set owners to full amount of total nr of pods.
Since we also have a bug that sometimes in our custom made provider, this happens, we conclude distributed cache is a bad implementation done by jboss or a bad usage of it by keycloak.

Therefore we switched to replicated cache and now all our issues are solved ! So seems that replicated cache is more reliable.
Since we also have big issue already for few years with blockage and timouts on all pods when deploying (restarting pods 1 by one), we hope also with replicated cache this improves. It seems that when getting above a certain amount of sessions (>300.000), distributed cache has problems determine where a session lives (even when putting owners on full amount) and a lot of timeouts occure. Will tell if also this issue is solved with switching to replicated cache.