Repository navigation
Inquiry regarding intermittent CODE_TO_TOKEN errors following Keycloak 26.5.7 upgrade #48873
Unanswered
michielpeeters
asked this question in
Q&A
Replies: 1 comment 1 reply
|
This sounds like it could be related to the persistent user sessions changes in 26.x. In 25.x, sessions were stored in Infinispan (in-memory), so the code exchange was basically instant. In 26.x, with persistent sessions, there's a DB write involved and if the brokered flow is fast enough, the Main Realm might try to exchange the code before the Customer Realm's session data is fully committed. A few things I'd check:
Also worth noting — are you seeing this consistently with specific IDPs (like Entra ID) or across all of them? Some IDPs complete the callback redirect faster than others, which could make the race window more likely. |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hello,
We are currently running Keycloak 25.0.6 in a production environment and are in the process of investigating an upgrade path to version 26.5.7. Our architecture utilizes a multi-tenant configuration: a primary "Main Realm" brokers authentication to multiple "Customer Realms," which house various Identity Providers (IDPs) such as Microsoft Entra ID and Google Workspace.
During our testing of version 26.5.7, we have encountered an intermittent issue that did not exist in version 25.0.6. Specifically, we are seeing occasional CODE_TO_TOKEN errors during the browser login flow when the Main Realm attempts to exchange an authorization code for a token from a Customer Realm.
We suspect this may be related to the transition toward Persistent User Sessions introduced in recent versions. Our primary hypothesis is a potential race condition: is it possible that the token data from the Customer Realm is being stored asynchronously or in parallel with the response sent back to the Main Realm? If the write operation to the database is not finalized before the Main Realm attempts the exchange, this could explain the exchange failure.
Environment Details:
Infrastructure: Azure Container Apps
Database: Azure Database for PostgreSQL (Flexible Server), version 14
Keycloak Versions: Transitioning from 25.0.6 to 26.5.7
Replica(s): 1, it even happens when it is not being setup in a multi-node setup.
Could you please clarify if there have been changes to the session persistence logic that might cause such a delay? Alternatively, if you have seen similar behavior in multi-tenant/brokered setups, any guidance on further debugging steps would be greatly appreciated.
Kind regards,
Michiel
All reactions