Memory Leak Problem in Keycloak

Hello Everyone,

We have a SPI java project that is using Keycloak. We have three different method. First two methods are creating a new user session in Keycloak. The last method is killing all of the opened sessions. After we setup the project in Openshift, we are running performance tests with high number of users(such as 400 request per second). However, after 36-48 hours the performance of the pod is decreasing and the pod is starting to down. To solve the problem, we used several tools to get heap dump (Java visual VM, MAT to analyze dump). In the memory graphs and dumps, we found out that our project has memory leak problem but we also suspect from Keycloak because of the high number of users. We are not sure about that is keycloak cache cleaned ? Maybe, the user sessions are not cleaning. We are also not sure about the user sessions. Another question is that can the cache cause to the memory leak ? I am adding several screenshots. Moreover, we configured standalone.xml file in openshift environment. Therefore, we have used some .cli commands. You can find these commands at the below of the question. These .cli commands are generally used to configure the keycloak cache. Is there anyone who can help us ? Is there any idea that you can tell us to find the source of the problem ? Thank you for your interest.

/subsystem=infinispan/cache-container=keycloak/replicated-cache=work/component=expiration: add(lifespan=66000,interval=100)
/subsystem=infinispan/cache-container=keycloak/distributed-cache=sessions/component=expiration: add(lifespan=66000,interval=100)
/subsystem=infinispan/cache-container=keycloak/distributed-cache=clientSessions/component=expiration: add(lifespan=66000,interval=100)
/subsystem=infinispan/cache-container=keycloak/distributed-cache=offlineSessions/component=expiration: add(lifespan=66000,interval=100)
/subsystem=infinispan/cache-container=keycloak/distributed-cache=offlineClientSessions/component=expiration: add(lifespan=66000,interval=100)
/subsystem=infinispan/cache-container=keycloak/distributed-cache=authenticationSessions/component=expiration: add(lifespan=66000,interval=100)
/subsystem=infinispan/cache-container=keycloak/distributed-cache=loginFailures/component=expiration: add(lifespan=66000,interval=100)
/subsystem=infinispan/cache-container=keycloak/distributed-cache=actionTokens/component=expiration: add(lifespan=66000,interval=100)

/subsystem=infinispan/cache-container=keycloak/distributed-cache=sessions: write-attribute(name=owners, value=${env.CACHE_OWNERS_COUNT:1})
/subsystem=infinispan/cache-container=keycloak/distributed-cache=offlineSessions: write-attribute(name=owners, value=${env.CACHE_OWNERS_COUNT:1})
/subsystem=infinispan/cache-container=keycloak/distributed-cache=loginFailures: write-attribute(name=owners, value=${env.CACHE_OWNERS_COUNT:1})
/subsystem=infinispan/cache-container=keycloak/distributed-cache=clientSessions: write-attribute(name=owners, value=${env.CACHE_OWNERS_COUNT:1})
/subsystem=infinispan/cache-container=keycloak/distributed-cache=offlineClientSessions: write-attribute(name=owners, value=${env.CACHE_OWNERS_COUNT:1})
/subsystem=infinispan/cache-container=keycloak/distributed-cache=actionTokens: write-attribute(name=owners, value=${env.CACHE_OWNERS_COUNT:1})
/subsystem=infinispan/cache-container=keycloak/distributed-cache=authenticationSessions: write-attribute(name=owners, value=${env.CACHE_OWNERS_AUTH_SESSIONS_COUNT:1})


/subsystem=infinispan/cache-container=keycloak/replicated-cache=work:write-attribute(name=statistics-enabled,value=true)
/subsystem=infinispan/cache-container=keycloak/distributed-cache=sessions:write-attribute(name=statistics-enabled,value=true)
/subsystem=infinispan/cache-container=keycloak/distributed-cache=authenticationSessions:write-attribute(name=statistics-enabled,value=true)
/subsystem=infinispan/cache-container=keycloak/distributed-cache=clientSessions:write-attribute(name=statistics-enabled,value=true)
/subsystem=infinispan/cache-container=keycloak/distributed-cache=loginFailures:write-attribute(name=statistics-enabled,value=true)
/subsystem=infinispan/cache-container=keycloak/distributed-cache=actionTokens:write-attribute(name=statistics-enabled,value=true)







1 Like

Hi keycloak team
We have similar issues on keycloak 12 and on keycloak 16
Is there any update on that one?

Br
A

Hi,
I am facing the same issue, have you found a solution? or detected the root cause?