Skip to content
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

Race condition in Azure Service Bus queue #43

Open
jamie94bc opened this issue Apr 28, 2016 · 7 comments
Open

Race condition in Azure Service Bus queue #43

jamie94bc opened this issue Apr 28, 2016 · 7 comments

Comments

@jamie94bc
Copy link

jamie94bc commented Apr 28, 2016

As mentioned by @moswald in #38 ...

  1. In parallel, Thread A calls EnqueueAsync() and Thread B calls DeleteQueueAsync()
  2. Thread A passes through EnsureQueueCreatedAsync(), ensuring _queueClient is not null
  3. Thread B deletes the queue, setting _queueClient to null
  4. Thread A tries to use _queueCleint which is now null

There's not really a nice way to handle this without locking. Couple of solutions:

Option 1

Wrap _queueClient in a property which throws a slightly different exception, leaving the user to retry.

Option 2

Implement retry logic (preferably in QueueBase).

@niemyjski
Copy link
Member

Could use the new ? null check keyword which will help prevent against this too. I'm trying to think of a scenario when you would ever want to delete a queue..

@jamie94bc
Copy link
Author

jamie94bc commented Apr 28, 2016

@niemyjski yeah I'm with you on that. I'd rather replace DeleteQueueAsync() with ClearQueueAsync()

@jamie94bc
Copy link
Author

? would silently fail, which wouldn't be fantastic behavior!

@niemyjski
Copy link
Member

Is this still an issue?

@jamie94bc
Copy link
Author

Yeah - it's different from #45 (another race condition in AzureServiceBusQueue)

@moswald
Copy link
Contributor

moswald commented Jun 20, 2016

It is an issue, but I don't know if it can be solved without using locks everywhere. I think the "correct" solution is to document that it's a dangerous method and shouldn't be used in multi-threaded environments. Once one part of your application determines the queue should be deleted, the rest of the application should be halted.

@niemyjski
Copy link
Member

@moswald would you mind updating the docs for this?

@niemyjski niemyjski added the Hacktoberfest Hacktoberfest label Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants