question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Service Bus - OperationCanceledException in exception received handler while closing the message receiver

See original GitHub issue

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 throws OperationCanceledException.
  • In the catch block, there is info about not propagating ObjectDisposedException 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 condition message == null is true, because loading of the message was skipped. And so it enters the if 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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:23 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
SeanFeldmancommented, Nov 9, 2019

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.

1reaction
joeyengcommented, Nov 7, 2019

@inkel This is not about version of .NET Core, but about version of ServiceBus Library. According to the merged PR above your comment, the fix will be in version 4.1.1 of Microsoft.Azure.ServiceBus. Current published version is 4.1.0. So you have to wait for the next release.

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

OperationCanceledException when sending to Service Bus
Internal Server Error: The server did not provide a meaningful reply ; this might be caused by a premature session shutdown.
Read more >
Troubleshoot AMQP errors in Azure Service Bus
This article provides some of the errors you receive when using AMQP with Azure Service Bus. They're all standard behaviors of the service....
Read more >
Azure ServiceBus errors in production log
We are running MassTransit in production with Azure ServiceBus (ASB) and we frequently get error logs related to the use of the Azure...
Read more >
[Solved]-"Task was canceled" errors on Azure website-C#
See the answer here: ASP.NET Web API OperationCanceledException when browser cancels the request. And the WebAPI bug here:.
Read more >
DueDelayedMessageProcessor prevents/delays shutdown
DueDelayedMessageProcessor [(null)] Exception thrown while moving matured delayed messages. for several minutes.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found