UnlockAsync fails with KV Error ETMPFAIL


I’m trying to implement locking and unlocking around a document access. Lock succeeds fine using GetAndLockAsync.

When I try to unlock with UnlockAsync I get an error message, even with multiple retries:

Message: "KV Error: {Name=“ETMPFAIL”, Description=“Temporary failure. Try again”, Attributes=“temp,retry-now”}

Any idea what is going wrong or how to fix?

If it is significant, the GetAndLockAsync and UnlockAsync are in separate invocations of :
using ( var bucket = await _cluster.OpenBucketAsync


Hi @SLam,

Could you post a minimum sample of the code that’s not doing what you expect? If it can be reproduced, it could be a bug.

Note that when unlocking, you need to provide the CAS retrieved when getAndLocking. That’s how it knows the unlock comes from the same actor. You might double check that you’re doing that.

Yes. That is what I am doing but it still fails.

I am performing this command in between the GetAndLockAsync and UnlockAsync:

                var upsertResult = await bucket
                    .MutateIn<IDictionary<string, T>>( id )
                    .WithCas( docLock.CAS )
                    .Upsert( key, value )

using the cas from the lock command. In the result of the upsert is a new cas value.

Which cas should I use when unlocking? The cas from the lock or the cas from the last mutation on the locked document?

My understanding is that every time a document is modified, it gets a new CAS value. Therefore, to unlock, you would use the CAS from the sub-document upsert. Is that what you’re currently doing?

Yes, that is what I am doing now but I still get an error when unlocking. I’ll try get an isolated example to share.
Thanks for following up :slightly_smiling_face:

Attached is a demo program that shows the problem I am having.
I’m using .net sdk 2.7.12

CBLockTest.zip (1.4 KB)

I saw your code and I think I know where the issue is.
So it looks like you first lock the document, then you do an update on the document by providing the CAS.
I believe this update with CAS operation would have already unlocked the document. So when you try to unlock the document again, you might be getting this error.
If you try locking the document, and then immediately unlocking, and let us know if this behaves correctly.

1 Like

Yes, if I immediately unlock it works.
Thanks for your help. I’ll remove the explicit unlock.