Issues with Keycloak and Infinispan Integration: Invalid Magic Number Error

Hi everyone,

I’m running into an issue while integrating Keycloak with Infinispan within an ECS container setup. Here’s a brief overview of my configuration:

  • Tasks: Two tasks in an ECS container, one for Keycloak and another for Infinispan.
  • Load Balancer:
    • Keycloak: https://auth.myorg.com
    • Infinispan: http://auth.myorg.com:11222

In my Keycloak cache configuration (cache-ispn.xml), I’ve set the remote-server host to auth.myorg.com. However, I encounter the following error:

vbnet

Copy code

2024-11-23 11:23:48,769 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: ISPN004003: Invalid magic number. Expected 0xa1 and received 0x48

Interestingly, this error doesn’t occur when I use the private IP address of the Infinispan task as the hostname in cache-ispn.xml.

Does anyone have any insights or suggestions on what might be causing this issue and how to resolve it?

Thanks in advance for your help!

Usually the “magic number” errors occur when there’s a mismatch between the Infinispan or JGroups versions.

As an aside, I’m not sure why you would have a single instance of Keycloak and single instance of Infinispan. Is this for a test? Why not just use multiple instances of Keycloak, with embedded Infinispan using persistent sessions. Don’t overcomplicate your deployment.

My goal is to implement caching capabilities in Keycloak for storing data from custom authentication SPIs. Additionally, I want to ensure that user sessions remain intact during updates or changes to the Keycloak instance, so users don’t have to log in again.

To achieve this, I set up Keycloak and Infinispan as separate entities. If Infinispan were embedded within Keycloak, it would be taken down whenever Keycloak deployment is updated, causing disruptions. By running Infinispan separately, I ensure it remains unaffected by Keycloak updates, preserving user sessions.

Am I missing something here ? I couldn’t find a lot of examples for Keycloak and Infinispan deployments, hence I’ve been improvising so far.

As @xgp already mentioned, you don’t need an external Infinispan server to keep sessions persistent, this was introduced with KC25 as preview and KC26 as supported feature. It’s here, out of the box, just go with the embedded Infinispan, this will reduce your personal headache level and increase confidence.

I also just published a video about persistent user sessions this morning:

2 Likes