Repository navigation
Race Condition Between Keycloak Events and Entity Availability #40047
Unanswered
stephane-segning
asked this question in
Q&A
Replies: 0 comments
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.
Issue Description
We're experiencing a race condition between Keycloak event triggers and entity availability in our webhook handling system. This affects both user creation and entity updates.
Original Issue with User Creation
As documented in issue #29, we discovered that Keycloak sometimes fires a
USER-CREATEevent before the user is actually available via the Admin API. When our webhook handler receives this event and attempts to query Keycloak for the user details, it results in a 404 error.Expanded Issue with Entity Updates
We've now identified a similar race condition pattern during entity updates:
Visual Representation
sequenceDiagram participant Client participant Keycloak participant EventSystem participant WebhookHandler Client->>Keycloak: Update entity Keycloak->>EventSystem: Trigger event (begins processing) par Parallel Processes EventSystem->>WebhookHandler: Deliver event WebhookHandler->>Keycloak: Query for entity details and Keycloak->>Keycloak: Complete entity update in database end Note over WebhookHandler: Receives outdated data or 404 error WebhookHandler->>WebhookHandler: Process potentially stale dataTechnical Questions
Is this a known behavior in Keycloak's event system? Are events intentionally triggered before database transactions are complete?
Are we implementing the webhook handling incorrectly? Should we be implementing some form of retry mechanism or delay?
Is there a recommended pattern for ensuring data consistency when working with Keycloak's event system?
Current Environment
Potential Solutions We've Considered
Has anyone else encountered this issue or have recommendations for addressing this race condition?
I've checked the issues but couldn't get help (#33194).
Thanks in advance for your insights!
All reactions