Skip to content

Azure: Handle blob-lease-acquire errors from response instead of exception #227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

richardkooiman
Copy link

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.)

@madelson madelson changed the base branch from master to release-2.5.1 December 4, 2024 02:14
@madelson
Copy link
Owner

madelson commented Dec 4, 2024

Thanks for contributing @richardkooiman !

@madelson madelson merged commit bd834f5 into madelson:release-2.5.1 Dec 4, 2024
1 check was pending
@richardkooiman
Copy link
Author

@madelson You're welcome and thanks for accepting and merging!

@madelson madelson added this to the 2.5.1 milestone Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants