DistributedLock
DistributedLock copied to clipboard
Azure: Handle blob-lease-acquire errors from response instead of exception
The Azure implementation of DistributedLock uses the Azure Storage SDK, which, by default, throws exceptions in case an operation failed (e.g. acquire blob lease). This works fine for scenarios where this is an actual exception (e.g. should not happen that blob x does not exist or that a lease has already been given to another client). However, in an application such as ours where we often want to acquire a distributed lock for a specific item/entity, this results in a throw and a catch to get to the conclusion the blob does not exist yet - which is not really an exceptional case but, actually in most scenarios, the expected case.
This change allows for a more graceful detection of these specific scenarios by not relying on the throw/catch mechanism, but instead get the error from the response (by using the existing parsing mechanism from the Azure Storage SDK).
Would like to hear what you, @madelson, think of this change and if it's something you're willing to accept to enhance the great library you provide. :)
(p.s. I ran all Azure tests and they are still passing after this change.)