arcus-azure / arcus.messaging

Messaging with Microsoft Azure in a breeze.
https://messaging.arcus-azure.net
MIT License
20 stars 11 forks source link

Unable to invoke the MessagePump Circuitbreaker #443

Open fgheysels opened 5 months ago

fgheysels commented 5 months ago

I have a project where I use Arcus.Messaging and where I make use of the new Circuitbreaker functionality.

During testing, I've noticed that the Circuitbreaker functionality doesn't kick in when requested. Logs of my application show this exception:

System.InvalidOperationException: The message processor is already running and needs to be stopped in order to perform this operation

This can be traced back to the StopProcessingMessagesAsync method of the AzureServiceBusMessagePump class. Apparently this exception is thrown in that try-block.

Further investigation showed that the stacktrace contains a reference to a method EnsureNotRunningAndInvoke which is a member method of ServiceBusProcessor class.

Looking at that code shows that the logic for removing an eventhandler on the ProcessMessageAsync and ProcessErrorAsync methods are calling this method. click

This means that the StopProcessingMessagesAsync method must first call the StopProcessingAsync method on the ServiceBusProcessor before removing the eventhandlers.

image

stijnmoreels commented 5 months ago

Think this will be resolved with #442

fgheysels commented 5 months ago

This remark on the ProcessMessageAsync event is actually a bit worrying

/// /// It is not recommended that the state of the processor be managed directly from within this handler; requesting to start or stop the processor may result in /// a deadlock scenario. ///

Because, that's what we're actually doing... When we call the circuitbreaker from within the ProcessMessageAsync eventhandler, we're actually stopping the processor.

stijnmoreels commented 5 months ago

Yes, saw that too - am working on your branch to fully use the message receiver instead.