ConsulClient.AcquireLock throws Consul.LockConflictException on Consul 1.0
totkov opened this issue · 2 comments
LockOptions options = new LockOptions("Application/Test") { SessionName = "TestSession", SessionTTL = new TimeSpan(0, 0, 30) }; Task result = client.AcquireLock(options); result.Wait();
When I run this code with Consul v.1.0 the program sometimes throws Consul.LockConflictException. If I use Consul v.0.8 I have no problems.
Exception screenshot
At line 266 of Lock.cs
, there is a LockConflictException
thrown if the retrieved pair's flags do not match the const LockFlagValue
which is used to indicate whether a key is used as a lock. I believe that is the only place where an exception of that type is thrown. I experienced this exception when I attempted to create a lock on the same key that I was also writing data to. To remedy this issue, I created another key (ex: _dataLockKey) that simply acted as a semaphore to indicate whether or not the corresponding data-holding key (ex: dataHoldingKey) value is available or on hold. Hopefully that makes sense.
Yes, this is the correct behavior and should happen in the Go SDK as well, which is what this is based off of. Alternatively, you may use the data key as the lock key as well but set the Flag value appropriately.