-
Notifications
You must be signed in to change notification settings - Fork 7.3k
duplicate key value violates unique constraint "constraint_offl_cl_ses_pk3" #39173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
yep, that's pretty annoying issue, check it please 👍 |
@ahus1 Do you mind helping with this one? |
@RadekSalay - perform the following steps
In addition, some more information is needed to analyze this:
|
Thanks for reporting this issue, but as this is reported against an older and unsupported release we are not able to evaluate the issue. Please verify with the nightly build or the latest release. If the issue can be reproduced in the nightly build or latest release add a comment with additional information, otherwise this issue will be automatically closed within 14 days. |
@RadekSalay - please also provide the complete list of start-up parameters for Keycloak, including the database parameters and the version of the database you are using. Thanks! |
Hi,
Start up parameters:
|
@RadekSalay - you say you updated to 26.1.1, but the latest version of 26.1.x is 26.1.5. Please update to 26.1.5, or even better update to 26.2.1 which is the latest version of the 26.2.x release branch to reproduce the problem. In the example you showed, it states offline_flag = 0, so this is not about the creation of an offline session (despite the table name, sorry for not yet having it renamed yet), but about an online session. I debugged the code in Keycloak 26.2, and the results should be similar in KC 26.1. It is possible if you are already logged in, and then add another client session concurrently in two separate tabs of the same browser, where the requests are executed in two different Keycloak instances, that both of them try to add the client session to the one user session. If this then fails for one of the two calls due to the database constraint, it will repeat the attempt which will then succeed, and therefore you don't see a 500 in the logs and the user also sees no error. So I consider this a log message that is unfortunately on the ERROR level, but then later recovered without a user impact. Assuming these are calls from a browser with a public client, you might be able to mitigate this by having sticky sessions in your loadbalancer where all requests from the same browser end on the same instance of Keycloak, which would then prevent a concurrent execution, but would run them consecutively thereby preventing the error. Depending on the event logging you might have set up, you should be able to retrieve different possibly concurrent events connected to the user session I'll prepare a change to prevent logging the error message if it is later recovered by disabling logging for Please let me know your thoughts on this. UPDATE: I think I can also filter out the warning ... let's see what the others say about my suggestion in the PR that is now connected to this issue. |
… are handled Closes keycloak#39173 Signed-off-by: Alexander Schwartz <aschwart@redhat.com>
… are handled Closes keycloak#39173 Signed-off-by: Alexander Schwartz <aschwart@redhat.com>
Hi, @ahus1 |
… are handled (keycloak#39344) Closes keycloak#39173 Signed-off-by: Alexander Schwartz <aschwart@redhat.com>
… are handled Closes keycloak#39173 Signed-off-by: Alexander Schwartz <aschwart@redhat.com>
… are handled Closes #39173 Signed-off-by: Alexander Schwartz <aschwart@redhat.com>
… are handled (keycloak#39344) Closes keycloak#39173 Signed-off-by: Alexander Schwartz <aschwart@redhat.com>
@sares001 - this issue was resolved for Keycloak 26.2.4 which was released last week. If the problem persists after you upgraded to 26.2.4 or later, please open a new bug issue. With the 26.1.x release of Keycloak this is a know behavior, although not visible to end users as Keycloak is retrying internally. |
@ahus1 Thank you, I will upgrade to 26.2.4 |
Uh oh!
There was an error while loading. Please reload this page.
Before reporting an issue
Area
infinispan
Describe the bug
Hi, not very often we find an error in database table app_keycloak.OFFLINE_CLIENT_SESSION.
Full error is
Batch entry 0 insert into app_keycloak.OFFLINE_CLIENT_SESSION (DATA,TIMESTAMP,VERSION,CLIENT_ID,CLIENT_STORAGE_PROVIDER,EXTERNAL_CLIENT_ID,OFFLINE_FLAG,USER_SESSION_ID) values ((.........)) was aborted: ERROR: duplicate key value violates unique constraint "constraint_offl_cl_ses_pk3"
I think the problem is that multiple instances of my Keycloak want to write offline_session to the database. Those who try to write later get an error from the database that such a session already exists. Which instance should write to the database should be controlled by the Infinispan cache. Which works correctly most of the time, because this error is only occasional.
Our Keycloak instances run in AKS. We use dns.DNS_PING for discovery with headless-service.
I try adding mode=SYNC and changing the number of owners in cache-ispn.xml for distributed-cache of offlineSessions, but the error still prevails.
In the logs of Jgroup I can see that pods successfully see each other.
Version
26.1.1
Regression
Expected behavior
Always only one instance of Keycloak will write offline sessions, so there will be no conflict in the database.
Actual behavior
Multiple instances of Keycloak try to write offline_session and only the first one is successful others end with error on duplicate keys.
How to Reproduce?
Anything else?
No response
The text was updated successfully, but these errors were encountered: