CodeNameNotUniqueException: The user with code name

L B asked on November 19, 2018 01:02

Hi,

Kentico version: v11.0.40

Issue close to what we got but not exactly (as ours is not about roles), and in version 7: https://devnet.kentico.com/questions/codenamenotuniqueexception-after-applying-hotfix-kentico-7

We put a new website in A/B testing and now that we have thousands of people using it we start to see some errors from Kentico. Some customers seems to not be able to login as they keep getting an error again and again while trying.

It happens when we use this method: AuthenticationHelper.AuthenticateUser(username, password, SiteContext.CurrentSiteName, true); http://devnet.kentico.com/docs/11_0/api/html/M_CMS_Membership_AuthenticationHelper_AuthenticateUser_1.htm

The exception:

    CMS.DataEngine.CodeNameNotUniqueException: The user with code name 'useremail@gmail.com' already exists.
at CMS.DataEngine.AbstractInfoProvider`3.SetInfo(TInfo info)
at CMS.Membership.UserInfoProvider.SetUserInfoInternal(UserInfo user)
at CMS.Membership.AuthenticationHelper.EnsureExternalUser(UserInfo uInfo)
at CMS.Membership.AuthenticationHelper.AuthenticateUser(String userName, String password, String siteName, Boolean login, AuthenticationSourceEnum source)

It is hard to replicate as it seems pretty random and to be a temporary thing, just long enough to make the customer leave the website.

Does anyone already got this kind of issue, or have information related to this issue ?

Thanks.

Correct Answer

L B answered on November 27, 2018 00:30

After speaking with the support it is a multi server issue,

Short answer: Enable the Webfarm as it enable a process of update the cache across servers.

Long answer:

All Kentico providers implement AbstractInfoProvider, which ultimately implement IInfoCacheProvider.

This cache provider put the object in a Kentico cache named HashTable (I don't think it is the same cache you can use with CacheHelper).

This cache is a dictionary style cache (key/value), it cache the user when there is a new one, or when someone login, but more importantly it caches the user when it is not there. (e.g. dictionary[key] = null).

So one of the scenario of what happened is: 1. A user try to login on his computer on server A, but he does not have any account, the custom authentication don't find him, set the user to null (the key is added to the HashTable cache with null)

  1. He then register with his phone on server B, which add the user to the CMS User table and add to the HashTable for server B only.

  2. He then try to login on his computer again on server A, the custom authentication find the user account, set the user (as per documentation). Finally the UserInfoProvider search for the user in its HashTable, find it with the value null, therefore it tries to add the user in the CMS User table like it is a new one. And crash due to the duplicate.

So there must be a process in the WebFarm module that probably notice the other servers to update their cache when the current server do.

Cheers.

0 votesVote for this answer Unmark Correct answer

Recent Answers


David te Kloese answered on November 19, 2018 09:06

Do you have multiple sites? Can you check this setting:

https://content.screencast.com/users/DavidTK/folders/Jing/media/faf9c9fd-a24f-4d87-8575-e23df2ba3675/2018-11-19_0901.png


Did you create a custom authentication with an External source? As I see part of your exception trace contains at CMS.Membership.AuthenticationHelper.EnsureExternalUser

Did you follow this https://docs.kentico.com/k10/custom-development/handling-global-events/handling-custom-external-authentication

Looks like you try to insert a user that you already have with that email.

0 votesVote for this answer Mark as a Correct answer

L B answered on November 20, 2018 00:29

Hi David,

It is not multisite, and indeed we use the custom authentication, our code is really similar to the one in the documentation. The whole login process hold within 50 lines, it is really basic, that's why we were surprised to see any issue.

My guess would be that the db cache is not registering the user due to whatever issue (can be anything there, from bug to system) and then the EnsureExternalUser is not doing its job properly.

I end contacting the support as it looks more like a bug than something else, I will post update if anything comes out of this, but as it is really hard to reproduce I'm not sure we will be able to get a solution for that.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.