Repository navigation
Description
Before reporting an issue
- I have read and understood the above terms for submitting issues, and I understand that my issue may be closed without action if I do not follow them.
Area
infinispan
Describe the bug
We are happy users of v1802 (18.0.2) for around 2 years now.
Recently org decided to migrate to higher versions, and so we currently trying out v2307 (23.0.7)
Following is how our test look
- JMeter creates 35 concurrent-users (CU) that are configured to login/logout every 3 seconds. This resulted in around 100k requests / hr at the loadbalancer (AWS ALB)
- We ran 35 CU for 2 hrs without any errors
- We then injected 25 more CUs in the same run .. again no errors (170 k requests / hr at ALB)
- We then stopped testing for half an hour before restarting 2nd test with just 35 CUs for 2 hrs (100k req / hr at ALB)
- With this 2nd run, we now observe around 3.25% errors (5XX) at JMeter.. We see these errors every time on the 2nd test (1st test is always clean.. no errors.. we tried this 5-6 times in the last one week)
Our Environment is
- DB is AWS Aurora RDS PostgresSQL multi-region cluster with KC connection pool size of 150
- KC v2307 is running in AWS EKS Pods (10 pods) running image built from quay.io/keycloak/keycloak:23.0.7
- Infinispan cluster is separate (again on AWS EKS) and we use custom infini configuration on KC side (there is no change in this configuration since v1802)
Main errors we see on infinispan side are ISPN000476, ISPN4003 and ISPN000299
5XX occurs when these errors start appearing on the 2nd test run
-
[pod/infinispan-cluster-deployment-66c4b5568-rbn58/infinispan-pod] 2024-08-24T05:07:36.093193510Z 2024-08-24 05:07:36,092 ERROR (non-blocking-thread--p2-t2) [org.infinispan.interceptors.impl.InvocationContextInterceptor] ISPN000136: Error executing command PutKeyValueCommand on Cache 'clientSessions', writing keys [WrappedByteArray[0304090000000E\j\a\v\a.\u\t\i\l.\U\U\I\DBC9903F798\m85/000000020000000C\l\e\a\s\t\S\i\g\B\i\t\s$000000000B\m\o\s\t\S\i\g\B\i... (85 bytes)]] org.infinispan.util.concurrent.TimeoutException: ISPN000476: Timed out waiting for responses for request 1306620 from infinispan-cluster-deployment-66c4b5568-2t2zn-18299 after 17.5 seconds
-
[pod/infinispan-cluster-deployment-66c4b5568-2t2zn/infinispan-pod] 2024-08-24T05:08:29.940089423Z 2024-08-24 05:08:29,939 ERROR (non-blocking-thread--p2-t2) [org.infinispan.interceptors.impl.InvocationContextInterceptor] ISPN000136: Error executing command ReplaceCommand on Cache 'clientSessions', writing keys [WrappedByteArray[0304090000000E\j\a\v\a.\u\t\i\l.\U\U\I\DBC9903F798\m85/000000020000000C\l\e\a\s\t\S\i\g\B\i\t\s$000000000B\m\o\s\t\S\i\g\B\i... (85 bytes)]] org.infinispan.util.concurrent.TimeoutException: ISPN000299: Unable to acquire lock after 50 milliseconds for key WrappedByteArray[0304090000000E\j\a\v\a.\u\t\i\l.\U\U\I\DBC9903F798\m85/000000020000000C\l\e\a\s\t\S\i\g\B\i\t\s$000000000B\m\o\s\t\S\i\g\B\i... (85 bytes)] and requestor CommandInvocation:infinispan-cluster-deployment-66c4b5568-2t2zn-18299:404844. Lock is held by CommandInvocation:infinispan-cluster-deployment-66c4b5568-2t2zn-18299:404680
-
[pod/kc-cluster-deployment-558d46db4c-b67nt/kc-pod] 2024-08-24T05:43:08.418112021Z 2024-08-24 05:43:08,417 WARN [org.infinispan.HOTROD] (Thread-0) ISPN004098: Closing connection [id: 0x33fa4421, L:/10.0.3.115:52050 - R:10.0.3.160/10.0.3.160:11333] due to transport error: org.infinispan.client.hotrod.exceptions.InvalidResponseException:: ISPN004003: Invalid magic number. Expected 0xa1 and received 0x1
-
ERROR [org.keycloak.services.error.KeycloakErrorHandler] (executor-thread-246) Uncaught server error: java.io.IOException: Read timed out
at org.jboss.resteasy.reactive.server.vertx.VertxInputStream$VertxBlockingInput.readBlocking(VertxInputStream.java:238) Terminating due to java.lang.OutOfMemoryError: Java heap space
In the first run, the KC pods run happy consuming only 100 millicores of CPU (5%-10%), while on the 2nd test run somehow the pod CPU consumption goes to almost 95% of the CPU (we tried 1 core/pod and 2 cores/pod configurations, both.. it goes to 95% for both the cases on 2nd test run).
Following is the sequence in which above errors seem to occur on the 2nd run
Pods CPU saturate to 95% consumption => pods start to crash and restart (due to OOM) => ISPN4003 => ISPN000476 => ISPN000299 => 5XXs
[All these infini errors get communicated to KC side as well causing a lot of EKS cluster bandwidth consumption]
We have tried following configration variations so far but no help so far
a) Infinispan side => mode=SYNC, acquire-timeout=50ms and concurrency=500 for caches clientSessions and sessions (all errors are currently seen limited to only these 2 caches)
b) Keycloak side => remote-timeout=200ms and owners=1 for caches clientSessions and sessions
- [currently trying below.. will inform if this solved our issue]
a) Infinispan side => mode=ASYNC for all caches (not only sessions and clientsessions), acquire-timeout=10ms and concurrency=1000 for caches clientSessions and sessions
b) Keycloak side => remote-timeout=200ms and owners=1 for caches clientSessions and sessions
We don't understand why this should happen on the second run only? Is there a way to prevent ISPN000476 and others (we are trying various infinispan configurations as above)? Is it a known issue with 2307? Should we migrate to v25 instead (would it help)?
Version
23.0.7
Regression
- The issue is a regression
Expected behavior
There should be no infinispan errors on the 2nd run.. We don't expect any 5XX errors due to these.
Actual behavior
Already described above.
How to Reproduce?
Described in the main writeup (prepare JMeter tests as we have described)
We can share our infinispan cluster and KC side infinispan configuration if required.
Anything else?
We have tried to look for solutions using following past discussions on the web.. but no relief yet.
- infinispan TimeoutException ISPN000299: Unable to acquire lock #15852
- https://stackoverflow.com/questions/59236742/communicating-infinispan-remote-exceptions-generates-excessive-network-traffic
- https://stackoverflow.com/questions/70879775/infinispan-client-hotrod-massive-put-data-ispn000476-timed-out-waiting-for-resp
Activity
atexela commentedon Aug 24, 2024
KC Pods are configured with request=1400M and limit=1400M of memory space.. this should be sufficient heap (as per documentation 70% of container memory is allocated to heap in quarkus distribution automatically), but in the security admin console we see only 455 M of space allocated
We wonder why 70% is not allocated automatically? We are ok with 70% if it can be seen allocated on the admin-console. Do we need to use JAVA_OPTS_KC_HEAP explicitly?
Cluster consumption situation at the moment when tests are finished (there is no load on the system (no tests running)).. you can see that the KC pods are still at highest CPU consumption (2 cores per pod config) even with no load..
High CPU consumption persisted for even after around 4 hours of the test finish.. what could be causing this?
I see following traces on the KC pods (even after 4 hours)
[pod/kc-cluster-deployment-558d46db4c-b67nt/kc-pod] 2024-08-24T05:48:26.814673627Z 2024-08-24 05:48:26,814 WARN [org.infinispan.HOTROD] (Thread-0) ISPN004005: Error received from the server: org.infinispan.util.concurrent.TimeoutException: ISPN000299: Unable to acquire lock after 50 milliseconds for key WrappedByteArray[0304090000000E\j\a\v\a.\u\t\i\l.\U\U\I\DBC9903F798\m85/000000020000000C\l\e\a\s\t\S\i\g\B\i\t\s$000000000B\m\o\s\t\S\i\g\B\i... (85 bytes)] and requestor CommandInvocation:infinispan-cluster-deployment-66c4b5568-2t2zn-18299:407725. Lock is held by CommandInvocation:infinispan-cluster-deployment-66c4b5568-2t2zn-18299:407692
[pod/kc-cluster-deployment-558d46db4c-b67nt/kc-pod] 2024-08-24T05:48:26.816082257Z 2024-08-24 05:48:26,815 ERROR [org.keycloak.services.error.KeycloakErrorHandler] (executor-thread-603) Uncaught server error: org.infinispan.client.hotrod.exceptions.HotRodClientException:Request for messageId=799650 returned server error (status=0x86): org.infinispan.util.concurrent.TimeoutException: ISPN000299: Unable to acquire lock after 50 milliseconds for key WrappedByteArray[0304090000000E\j\a\v\a.\u\t\i\l.\U\U\I\DBC9903F798\m85/000000020000000C\l\e\a\s\t\S\i\g\B\i\t\s$000000000B\m\o\s\t\S\i\g\B\i... (85 bytes)] and requestor CommandInvocation:infinispan-cluster-deployment-66c4b5568-2t2zn-18299:407725. Lock is held by CommandInvocation:infinispan-cluster-deployment-66c4b5568-2t2zn-18299:407692
[pod/kc-cluster-deployment-558d46db4c-b67nt/kc-pod] 2024-08-24T05:48:44.265038526Z 2024-08-24 05:48:44,264 WARN [org.infinispan.HOTROD] (Thread-0) ISPN004005: Error received from the server: org.infinispan.util.concurrent.TimeoutException: ISPN000476: Timed out waiting for responses for request 1311833 from infinispan-cluster-deployment-66c4b5568-2t2zn-18299 after 17.5 seconds
[pod/kc-cluster-deployment-558d46db4c-b67nt/kc-pod] 2024-08-24T05:48:44.267666166Z 2024-08-24 05:48:44,267 ERROR [org.keycloak.services.error.KeycloakErrorHandler] (executor-thread-593) Uncaught server error: org.infinispan.client.hotrod.exceptions.HotRodClientException:Request for messageId=799649 returned server error (status=0x86): org.infinispan.util.concurrent.TimeoutException: ISPN000476: Timed out waiting for responses for request 1311833 from infinispan-cluster-deployment-66c4b5568-2t2zn-18299 after 17.5 seconds
atexela commentedon Aug 27, 2024
Turning infinispan cache replication mode to ASYNC for all caches on infinispan side did seem to help a little bit.
This time following sequence occured after 7 hrs of test run and the problems occured in the 3rd cycle.
infinispan pods crashed (due to OOM) => KC pods showed exceptions => infini pods came up => KC pods crashed due to ISPN errors followed by OOM (as before) => All pods stabilized after 45 minutes.
Exception details are below
- Immediately after infinispan crash
- After infini pods came back up
Runs and 5XX erros as seen on our ALB are below.
requests/minute
5XXs/minute
this time, all problems seem to have begun after infinispan crashed.
We are next trying to increase infinispan memory to prevent it from crashing... may be it will stabilize things for us.
In the meantime, let us know what community think.
atexela commentedon Aug 27, 2024
We are shifting focus to testing latest release now v25.0.4 and report whether we could reproduce these issues there.
Just to update the current sequence of testing on 2307.. increasing infinispan memory did prevent infini pods crashes this time. However, the old error sequence came back
KC Pods CPU saturate to 95% consumption => KC pods start to crash and restart (due to OOM) => ISPN4003 => ISPN000476 => ISPN000299 => 5XXs
Will continue on 2504 now.
36 remaining items
atexela commentedon Sep 11, 2024
we have tested 2504 with changed infinispan configuration because the configuration (that we use on our production with 1802) doesn't work with the new release and was causing many errors. the only changes we've made were are as follows (to prevent lock exceptions that we started getting on the new release... we never saw them on 1802)
also, we feel that as long as KC documentation has --cache-config-file option, it must be supported.
we'd appreciate if someone could respond to the misconfiguration that you've observed in the XMLs that we used in our testing.
we might consider cockroachDB for multi-region then (if async replication that aurora provides is not supported).. however, it is far on our roadmap, to go multi-region. we are already multi AZ setup.
thanks for guidance wrt http-pool-threads
we will ensure sufficient memory for the 2504 release. for KC26, we will consider persistent sessions.
ahus1 commentedon Sep 11, 2024
Thank you for the additional context.
As you mention
cache-config-fileis supported to specify a custom XML file for things that are not supported on the Keycloak command line. At the same time the XML file file allows all possible values Infinispan allows, and not all of them are compatible with Keycloak. Looking at thecache-custom.xml, I assume all of the modifications can be achieved using the CLI optionscache-remote-host,cache-remote-password,cache-remote-port,cache-remote-tls-enabledandcache-remote-username. Please verify and confirm.For Keycloak and external Infinispan, the supported setup is to use SYNC, and leave remote-timeout and acquire-timeout at the defaults. ASYNC replication will lead to inconsistencies which will show later in strange invalid data errors.
To deploy Infinispan 15 with the Operator, there is a setup here https://www.keycloak.org/high-availability/deploy-infinispan-kubernetes-crossdc which focuses on a multi-site setup. For a single-site setup, you might leave out the multi-site related parts and all references to "backups" and all references to the gossip router. While using an external Infinispan for a single-site setup is not supported, it might still be a good starting point for you.
Please report back once you have configured Keycloak to not use a customer XML file and Infinispan in version 15, or when you run into problems when doing this. If you don't consider running Infinispan with its Operator, let us know why you don't want to apply it.
Another thought to the earlier OOM-recovery you saw on KC18: Maybe in such a setup the number of owners was set to 1, so that the sessions stored on the OOM node would be lost. When configured to be with owners set to 2, no sessions are lost, and on OOM the existing sessions are distributed to the remaining nodes, which increases the memory pressure on those. This might then explain the behavior your see on OOM.
CockroachDB is currently not supported and known to not work with standard Keycloak. There are customizations from others, but they are not supported by the main Keycloak project.
atexela commentedon Sep 14, 2024
Thanks for responding and reopening this.
We tried ASYNC and other values for remote/acquire-timeout(s) because original (SYNC and defaults) were causing inconsistencies while testing v25 (and the other higher release), but we now realize that it was primarily because of OOMs.
With v25, we have now realized that we need to maintain sufficient memory buffers matching the expected load (X 2 may be). We should not expect it to run like v18 that was more resilient wrt memory shortages.
Thanks for sharing this, we will attempt it with v26 or higher when we decide to make the next jump (and will also performance test persistent-user-sessions setup (without infinispan)). For now we are thinking of moving to prod with sufficient memory buffer and no change in infinispan setup that we currently use with v18 (2 owners, SYNC and defaults for acquire/remote-timeouts).
We usually prefer k8s configuration that we can touch, feel and control, and is not hidden behind an operator/custom-resource. However, this can change in future if we find it too difficult to configure things on our own.
No we used 2 owners on v18 (on prod), but in order to fix inifni problems with v25 (and the other higher release we tested), we gradually started making changes to infini configuration.. 2 owners to 1, SYNC to ASYNC .. and so on . It was based on the articles about related issues that we were reading about on the net. However, as I mentioned.. we will most likely go to v25 in prod with sufficient memory and original infini settings on 14. Most likely all problems were because of memory.
Cockroach is costly as well.. May be then we'll use multi site postgreSQL in multi-active/multi-master setup. It is far on our roadmap as I mentioned earlier, and perhaps will take a lot of work to setup.
https://dimitrij-pankratz.medium.com/postgresql-multi-active-replication-part-1-an-introduction-ff7052eb9fd0#:~:text=PostgreSQL%20Replication&text=It%20is%20a%20method%20of,fault%20tolerance%20within%20database%20systems.
We are also considering to contribute to the keycloak project. It might take sometime though.
Thanks Again!!
Please close it if needed.
ahus1 commentedon Sep 15, 2024
Thank you for this summary. This now sounds like you're now on a good way. Can this issue then be closed?
If you want to have a setup that allows to "breathe", you might want to consider a deployment that scales between 3 and 6 Pods, while the number of http threads is configured for the maximum of 6 Pods. BTW, in the Keycloak Benchmark Project, we usually test with either 3 or 6 Pods. For higher number, one would need to tune the JGroups number of threads, and that adds another layer of complexity. We're looking into this to remove the need to configure this for future versions of Keycloak.
On your road to contributions, please consider your feedback what works and what doesn't already a contribution. If you should find items in the documentation that are missing and should be clarified, consider a PR or start with a bug issue.
We recently announced a Keycloak SRE special interest group. The goal is to steer the Keycloak development and coordinate contributions to Keycloak to make it simpler to run. While we can't work an all the areas all he time, we'll start with load balancing. Maybe you have the time to follow this one.
atexela commentedon Sep 16, 2024
In prod with v18, we have autoscale from 3 to 10 (based on average vCPU > 60%).... however, for this performance testing on v25 in uat, we fixed it to 10 to observe crash/restart behavior (no autoscale). Could you please inform the autoscale criteria that you would recommend? is vCPU > 60% good?
could you pls share the recommended value for http-pool-max-threads that you used with 6 pods in your benchmark? would 100 be good?
also, for this testing we had increased max db connection pool size from 100 (default) to 200 but we still saw those connection acquire errors followed by DB transaction reapers after OOM conditions (with CPU maxing out)... what would be the recommended value for connection pool size for 6 pods.. again I still believe that 100 should be okay per pod, but perhaps we need to increase this from Aurora DB side as well if multiple pods are running (we did not do it that in this testing.. may be that is why we saw connection acquire errors [Edit 17Sep : the max connections on AWS aurora side were found to be okay at 1000 (we are at serverless ACU=8) so at least AWS aurora is ruled out as root cause]).
So far, we don't configure it explicitly, but assume that, if needed, it needs to be configured on < TCP > protocol element of our infini side configuration above (as per http://www.jgroups.org/schema/jgroups-4.2.xsd). default I believe is 100 threads.
So, all in all, a cap at 100 threads for http-thread-pool per pod, a cap of 100 on db-connection-pool per pod, >=1000 threads on JGroups (to accomodate load from 10 pods), and a >1000 connections configuration on Aurora RDS DB side (to accomodate 100 pooled connections per pod, from 10 pods) should fix connection errors?? right? would appreciate response on this
This is just great! Thanks for starting this. I will definitely follow-up on it.
After the responses to above, you can close this as needed.
ahus1 commentedon Sep 18, 2024
While a deployment with the Keycloak Operator supports auto-scaling via HPA, we don't provide a blueprint how to do this.
With 200 JGroups threads, and 6 Pods max, we recommend
http-pool-max-threadsto be 200 / 6 = 33. See https://www.keycloak.org/high-availability/concepts-threads for the formula.While this is the JGroups default, it is not the Infinispan default. See the docs above that this is 200.
A number of DB connections should be the same as
http-pool-max-threads, as one request usually uses one DB connection except in some rare conditions where uses nested transactions, where it is two.atexela commentedon Apr 7, 2025
this is just to inform that we migrated successfully to 26.1.0 recently. it is working good in production, but it has functional issues #38495