5

I'm having an issue identifying xDB contacts... I'm trying to call the Identify() method in my controller action, but I see this error in the logs:

Exception: System.InvalidOperationException Message: A contact is locked by another operation.

What am I doing wrong?

EDIT: Here's the full stack trace.

Exception: System.InvalidOperationException Message: A contact is locked by another operation. Source: Sitecore.Analytics.MongoDB at Sitecore.Analytics.Data.DataAccess.MongoDb.MongoDbContactStorage.LoadContactIdentifier(ID contactId, LeaseOwner leaseOwner) at Sitecore.Analytics.Data.DataAccess.MongoDb.MongoDbDataAdapterProvider.SaveContactWithIdentifier(IContact contact, ContactSaveOptions saveOptions) at Sitecore.Analytics.Data.DataAccess.MongoDb.MongoDbDataAdapterProvider.<>c__DisplayClass9.b__7() at Sitecore.Analytics.Data.DataAccess.MongoDb.MongoDbDataAdapterProvider.Try(Action action) at Sitecore.Analytics.Data.DataAccess.MongoDb.MongoDbDataAdapterProvider.SaveContact(IContact contact, ContactSaveOptions saveOptions) at Sitecore.Analytics.Data.ContactRepository.SaveContact(Contact contact, ContactSaveOptions options) at Sitecore.Analytics.Tracking.ContactManager.SubmitContact(Contact contact, ContactSaveOptions options)

5
  • 1
    Can you post a bit more of the stack trace, please? Oct 3, 2016 at 21:19
  • 1
    Updated original question with the full stack trace. Oct 3, 2016 at 21:20
  • 1
    Is this a duplicate question? stackoverflow.com/questions/33235368/…
    – Anicho
    Oct 3, 2016 at 22:52
  • 1
    certainly wasn't intended as a duplicate, but it's a common issue many Sitecore devs run in to. Oct 3, 2016 at 23:06
  • I can't link as duplicate anyway, posted answer and source to original below.
    – Anicho
    Oct 3, 2016 at 23:14

2 Answers 2

10

Source: https://stackoverflow.com/questions/33235368/sitecore-current-contact-is-locked-for-identification

Why this happens

Normally, you will see this error when you forget to set Analytics.ClusterName in the configuration file Sitecore.Analytics.Tracking.config. This becomes a problem because in the beginning of every session Sitecore lock the current contact by creating a Lease in xDB. It uses Analytics.ClusterName as the identifier of the lock.

The error you are seeing occurs because your Sitecore instance doesn't realize that it owns the lease on the contact since the lease owner identifier is missing.

If you look at your contact in the collection database, you are likely to see something like this:

enter image description here

As you can see, the Owner document does not have the Identifier field set. This indicates that the entity that created the lease did not provide an identifier (its value was an empty string or null).

Solution

To solve this in a development environment, just set both Analytics.ClusterName and Analytics.HostName setting values to the local domain name you're using when accessing the application, e.g. ``sitecore.

<setting name="Analytics.ClusterName" value="sitecore" />
<setting name="Analytics.HostName" value="sitecore" />

You can read more about these settings here.

UPDATE: Sitecore has added a knowledge base article about this issue: https://kb.sitecore.net/articles/965127

1
2

To add to Anicho's answer, if you correct the configuration any existing locked sessions will throw errors until the current lease expires. To speed this up, you can execute the following against your analytics database:

db.getCollection('Contacts').update(
    { "$and": [ 
        { "Lease.Owner.Type" :  {$eq:0} }, 
        { "Lease.Owner.Identifier" :  {$exists: false} } 
    ]},
    { $set: { "Lease" : null } },
    { multi: true }
)

This will drop any leases that were owned by a web cluster but don't have an identifier. Run this after you change the config (and before if you really want to minimise errors)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.