azure-sdk-for-net: [BUG] Service Bus - OperationCanceledException in exception received handler while closing the message receiver
Describe the bug
I have a QueueClient
for receiving messages (basically using it just as MessageReceiver
). It is working as expected - the messages are being processed. When I want to stop receiving messages, I call QueueClient.CloseAsync()
. There are still messages in the queue, so I will stop the receiver in the middle of the work. So the receiver/client is in the closing state, and I (almost) alway get an error in my ExceptionReceivedHandler
- it is OperationCanceledException
with the simple message “The operation was canceled.”.
Exception or Stack Trace
I do not have a direct exception. Just the exception from ExceptionReceivedEventArgs
. The call stack in the received exception is:
at System.Threading.CancellationToken.ThrowOperationCanceledException()
at System.Threading.SemaphoreSlim.WaitUntilCountOrTimeoutAsync(TaskNode asyncWaiter, Int32 millisecondsTimeout, CancellationToken cancellationToken)
at Microsoft.Azure.ServiceBus.MessageReceivePump.MessagePumpTaskAsync()
To Reproduce
Just stop MessageReceiver
while there still are messages in the queue to process and look in your exception handler.
Expected behavior
I am not really sure about it. But I think that if the client is in closing state, I should not get this type of error in my error handler (ExceptionReceivedHandler
). It is just annoying, because basically, I will get this error every time I am stopping my receiver.
Setup (please complete the following information):
- OS: Windows 10
- IDE : Visual Studio 2019
- Version of the Library used: Microsoft.Azure.ServiceBus 3.4.0
Additional context I attached the source of Microsoft.Azure.ServiceBus to dig deeper what is going on.
- The system throws while trying to get semaphore lock. The receiver is in closing state:
pumpCancellationToken.IsCancellationRequested == true
. So the semaphore throwsOperationCanceledException
. - In the
catch
block, there is info about not propagatingObjectDisposedException
when the pump is stopping. - I think, that this situation with
OperationCanceledException
is the same and it should not be reported too. - The final note is, that it later comes into the
finally
block. The conditionmessage == null
istrue
, because loading of the message was skipped. And so it enters theif
and releases semaphore lock. I am not sure about this, but I think the lock was not taken (semaphore threw exception), so probably it should not be released.
Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- Bug Description Added
- Repro Steps Added
- Setup information Added
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 23 (8 by maintainers)
Commits related to this issue
- [ServiceBus] Avoid reporting OperationCanceledException in message pump (#7935) When the pump is being shut down, Cancel is called on pumpCancellationToken, which eventually throws OperationCanceledE... — committed to Azure/azure-sdk-for-net by nemakam 5 years ago
- [ServiceBus] Ignore OperationCanceledException while closing Message Pump (#8449) * Ignoring OperationCanceledException when pump is stopping. * Updating changelog and version to 4.1.1 * Fix for #6... — committed to Azure/azure-sdk-for-net by nemakam 5 years ago
This is something that would need to be implemented on the GitHub side. Alternatively, you can create a filter in your inbox or subscribe to a NuGet notification with a feed I’ve created https://libraries.io/nuget/Microsoft.Azure.ServiceBus/versions.atom. I’m using IFTTT with the feed to notify in Slack @nemakam.
Is there a way to get notified of Microsoft.Azure.ServiceBus releases specifically instead of getting notifications for everything in the azure-sdk-for-net repo?