azure-sdk-for-net
azure-sdk-for-net copied to clipboard
[QUERY] Calling CloseAsync() or DisposeAsync() on ServiceBusProcessor throws exception with reason ServiceBusFailureReason.MessagingEntityNotFound
Library name and version
Azure.Messaging.ServiceBus 7.17.5
Query/Question
I keep track of topic subscriptions in a concurrent dictionary:
private readonly ConcurrentDictionary<string, ServiceBusProcessor> _subscriptions = new();
and when I want to clear out an entry from _subscriptions, I call CloseAsync() on the ServiceBusProcessor associated with the topic.
var removed = _subscriptions.TryRemove(topicName, out var servicBusProcessor);
if (servicBusProcessor!= null)
{
await servicBusProcessor.CloseAsync();
}
The call await servicBusProcessor.CloseAsync(); throws ServiceBusException with the reason: ServiceBusFailureReason.MessagingEntityNotFound
Is that normal behavior? I wouldn't expect an exception.
Environment
Windows 11, .NET 8
Thank you for your feedback. Tagging and routing to the team member best able to assist.
Hi @exciting-prism. Thanks for reaching out and we regret that you're experiencing difficulties. Can you please share the full error message and stack trace that you're seeing?
Hi @exciting-prism. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.
Here is the call stack filtered for Azure.Messaging.ServiceBus
as we said the exception is of type: ServiceBusException
and the exception.Reason is: ServiceBusFailureReason.MessagingEntityNotFound
Azure.Messaging.ServiceBus.dll!Azure.Messaging.ServiceBus.ServiceBusProcessor.OnProcessErrorAsync(Azure.Messaging.ServiceBus.ProcessErrorEventArgs args) Unknown
Azure.Messaging.ServiceBus.dll!Azure.Messaging.ServiceBus.ReceiverManager.RaiseExceptionReceived(Azure.Messaging.ServiceBus.ProcessErrorEventArgs eventArgs) Unknown
Azure.Messaging.ServiceBus.dll!Azure.Messaging.ServiceBus.ReceiverManager.ReceiveAndProcessMessagesAsync(System.Threading.CancellationToken cancellationToken) Unknown
[Resuming Async Method]
[Completed] Azure.Messaging.ServiceBus.dll!Azure.Messaging.ServiceBus.ServiceBusReceiver.ReceiveMessagesAsync(int maxMessages, System.TimeSpan? maxWaitTime, bool isProcessor, System.Threading.CancellationToken cancellationToken) Unknown
[Completed] Azure.Messaging.ServiceBus.dll!Azure.Messaging.ServiceBus.Amqp.AmqpReceiver.ReceiveMessagesAsync(int maxMessages, System.TimeSpan? maxWaitTime, System.Threading.CancellationToken cancellationToken) Unknown
[Completed] Azure.Messaging.ServiceBus.dll!Azure.Messaging.ServiceBus.ServiceBusRetryPolicy.RunOperation<(Azure.Messaging.ServiceBus.Amqp.AmqpReceiver, int, System.TimeSpan?), System.Collections.Generic.IReadOnlyList<Azure.Messaging.ServiceBus.ServiceBusReceivedMessage>>(System.Func<(Azure.Messaging.ServiceBus.Amqp.AmqpReceiver, int, System.TimeSpan?), System.TimeSpan, System.Threading.CancellationToken, System.Threading.Tasks.ValueTask<System.Collections.Generic.IReadOnlyList<Azure.Messaging.ServiceBus.ServiceBusReceivedMessage>>> operation, (Azure.Messaging.ServiceBus.Amqp.AmqpReceiver, int, System.TimeSpan?) t1, Azure.Messaging.ServiceBus.Core.TransportConnectionScope scope, System.Threading.CancellationToken cancellationToken, bool logTimeoutRetriesAsVerbose) Unknown
[Completed] Azure.Messaging.ServiceBus.dll!Azure.Messaging.ServiceBus.Amqp.AmqpReceiver.ReceiveMessagesAsync.AnonymousMethod__44_0((Azure.Messaging.ServiceBus.Amqp.AmqpReceiver, int maxMessages, System.TimeSpan? maxWaitTime) value, System.TimeSpan timeout, System.Threading.CancellationToken token) Unknown
[Completed] Azure.Messaging.ServiceBus.dll!Azure.Messaging.ServiceBus.Amqp.AmqpReceiver.ReceiveMessagesAsyncInternal(int maxMessages, System.TimeSpan? maxWaitTime, System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken) Unknown
[Completed] Microsoft.Azure.Amqp.dll!Microsoft.Azure.Amqp.Singleton<Microsoft.Azure.Amqp.ReceivingAmqpLink>.GetOrCreateAsync(System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken) Unknown
[Async Call Stack]
[Async] Azure.Messaging.ServiceBus.dll!Azure.Messaging.ServiceBus.ServiceBusProcessor.ReceiveAndProcessMessagesAsync(Azure.Messaging.ServiceBus.ReceiverManager receiverManager, System.Threading.CancellationToken cancellationToken) Unknown
[Async] System.Private.CoreLib.dll!System.Threading.Tasks.Task.WhenAll Unknown
[Async] Azure.Messaging.ServiceBus.dll!Azure.Messaging.ServiceBus.ServiceBusProcessor.RunReceiveTaskAsync(System.Threading.CancellationToken cancellationToken) Unknown
[Async] Azure.Messaging.ServiceBus.dll!Azure.Messaging.ServiceBus.ServiceBusProcessor.StopProcessingAsync(System.Threading.CancellationToken cancellationToken) Unknown
[Async] Azure.Messaging.ServiceBus.dll!Azure.Messaging.ServiceBus.ServiceBusProcessor.CloseAsync(System.Threading.CancellationToken cancellationToken) Unknown
Here is the full call stack with system runtime calls in case more details are needed:
Azure.Messaging.ServiceBus.dll!Azure.Messaging.ServiceBus.ServiceBusProcessor.OnProcessErrorAsync(Azure.Messaging.ServiceBus.ProcessErrorEventArgs args) Unknown
Azure.Messaging.ServiceBus.dll!Azure.Messaging.ServiceBus.ReceiverManager.RaiseExceptionReceived(Azure.Messaging.ServiceBus.ProcessErrorEventArgs eventArgs) Unknown
Azure.Messaging.ServiceBus.dll!Azure.Messaging.ServiceBus.ReceiverManager.ReceiveAndProcessMessagesAsync(System.Threading.CancellationToken cancellationToken) Unknown
[Resuming Async Method]
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.AsyncStateMachineBox<Azure.Messaging.ServiceBus.ReceiverManager.<ReceiveAndProcessMessagesAsync>d__13>.ExecutionContextCallback(object s) Unknown
System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.AsyncStateMachineBox<Azure.Messaging.ServiceBus.ReceiverManager.<ReceiveAndProcessMessagesAsync>d__13>.MoveNext(System.Threading.Thread threadPoolThread) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.AsyncStateMachineBox<Azure.Messaging.ServiceBus.ReceiverManager.<ReceiveAndProcessMessagesAsync>d__13>.MoveNext() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__12_0(System.Action innerContinuation, System.Threading.Tasks.Task innerTask) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action action, bool allowInlining) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishSlow(bool userDelegateExecute) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.TrySetException(object exceptionObject) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Collections.Generic.IReadOnlyList<Azure.Messaging.ServiceBus.ServiceBusReceivedMessage>>.SetException(System.Exception exception, ref System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<Azure.Messaging.ServiceBus.ServiceBusReceivedMessage>> taskField) Unknown
[Completed] Azure.Messaging.ServiceBus.dll!Azure.Messaging.ServiceBus.ServiceBusReceiver.ReceiveMessagesAsync(int maxMessages, System.TimeSpan? maxWaitTime, bool isProcessor, System.Threading.CancellationToken cancellationToken) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.__Canon>.AsyncStateMachineBox<Azure.Messaging.ServiceBus.ServiceBusReceiver.<ReceiveMessagesAsync>d__42>.ExecutionContextCallback(object s) Unknown
System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Collections.Generic.IReadOnlyList<Azure.Messaging.ServiceBus.ServiceBusReceivedMessage>>.AsyncStateMachineBox<Azure.Messaging.ServiceBus.ServiceBusReceiver.<ReceiveMessagesAsync>d__42>.MoveNext(System.Threading.Thread threadPoolThread) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.__Canon>.AsyncStateMachineBox<Azure.Messaging.ServiceBus.ServiceBusReceiver.<ReceiveMessagesAsync>d__42>.MoveNext() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__12_0(System.Action innerContinuation, System.Threading.Tasks.Task innerTask) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action action, bool allowInlining) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishSlow(bool userDelegateExecute) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.TrySetException(object exceptionObject) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Collections.Generic.IReadOnlyList<Azure.Messaging.ServiceBus.ServiceBusReceivedMessage>>.SetException(System.Exception exception, ref System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<Azure.Messaging.ServiceBus.ServiceBusReceivedMessage>> taskField) Unknown
[Completed] Azure.Messaging.ServiceBus.dll!Azure.Messaging.ServiceBus.Amqp.AmqpReceiver.ReceiveMessagesAsync(int maxMessages, System.TimeSpan? maxWaitTime, System.Threading.CancellationToken cancellationToken) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.__Canon>.AsyncStateMachineBox<Azure.Messaging.ServiceBus.Amqp.AmqpReceiver.<ReceiveMessagesAsync>d__44>.ExecutionContextCallback(object s) Unknown
System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Collections.Generic.IReadOnlyList<Azure.Messaging.ServiceBus.ServiceBusReceivedMessage>>.AsyncStateMachineBox<Azure.Messaging.ServiceBus.Amqp.AmqpReceiver.<ReceiveMessagesAsync>d__44>.MoveNext(System.Threading.Thread threadPoolThread) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.__Canon>.AsyncStateMachineBox<Azure.Messaging.ServiceBus.Amqp.AmqpReceiver.<ReceiveMessagesAsync>d__44>.MoveNext() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__12_0(System.Action innerContinuation, System.Threading.Tasks.Task innerTask) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action action, bool allowInlining) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishSlow(bool userDelegateExecute) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.TrySetException(object exceptionObject) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Collections.Generic.IReadOnlyList<Azure.Messaging.ServiceBus.ServiceBusReceivedMessage>>.SetException(System.Exception exception, ref System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<Azure.Messaging.ServiceBus.ServiceBusReceivedMessage>> taskField) Unknown
[Completed] Azure.Messaging.ServiceBus.dll!Azure.Messaging.ServiceBus.ServiceBusRetryPolicy.RunOperation<(Azure.Messaging.ServiceBus.Amqp.AmqpReceiver, int, System.TimeSpan?), System.Collections.Generic.IReadOnlyList<Azure.Messaging.ServiceBus.ServiceBusReceivedMessage>>(System.Func<(Azure.Messaging.ServiceBus.Amqp.AmqpReceiver, int, System.TimeSpan?), System.TimeSpan, System.Threading.CancellationToken, System.Threading.Tasks.ValueTask<System.Collections.Generic.IReadOnlyList<Azure.Messaging.ServiceBus.ServiceBusReceivedMessage>>> operation, (Azure.Messaging.ServiceBus.Amqp.AmqpReceiver, int, System.TimeSpan?) t1, Azure.Messaging.ServiceBus.Core.TransportConnectionScope scope, System.Threading.CancellationToken cancellationToken, bool logTimeoutRetriesAsVerbose) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Collections.Generic.IReadOnlyList<Azure.Messaging.ServiceBus.ServiceBusReceivedMessage>>.AsyncStateMachineBox<Azure.Messaging.ServiceBus.ServiceBusRetryPolicy.<RunOperation>d__23<(Azure.Messaging.ServiceBus.Amqp.AmqpReceiver, int, System.TimeSpan?), System.Collections.Generic.IReadOnlyList<Azure.Messaging.ServiceBus.ServiceBusReceivedMessage>>>.ExecutionContextCallback(object s) Unknown
System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Collections.Generic.IReadOnlyList<Azure.Messaging.ServiceBus.ServiceBusReceivedMessage>>.AsyncStateMachineBox<Azure.Messaging.ServiceBus.ServiceBusRetryPolicy.<RunOperation>d__23<(Azure.Messaging.ServiceBus.Amqp.AmqpReceiver, int, System.TimeSpan?), System.Collections.Generic.IReadOnlyList<Azure.Messaging.ServiceBus.ServiceBusReceivedMessage>>>.MoveNext(System.Threading.Thread threadPoolThread) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.__Canon>.AsyncStateMachineBox<Azure.Messaging.ServiceBus.ServiceBusRetryPolicy.<RunOperation>d__23<(System.__Canon, int, System.TimeSpan?), System.__Canon>>.MoveNext() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__12_0(System.Action innerContinuation, System.Threading.Tasks.Task innerTask) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action action, bool allowInlining) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishSlow(bool userDelegateExecute) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.TrySetException(object exceptionObject) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Collections.Generic.IReadOnlyList<Azure.Messaging.ServiceBus.ServiceBusReceivedMessage>>.SetException(System.Exception exception, ref System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<Azure.Messaging.ServiceBus.ServiceBusReceivedMessage>> taskField) Unknown
[Completed] Azure.Messaging.ServiceBus.dll!Azure.Messaging.ServiceBus.Amqp.AmqpReceiver.ReceiveMessagesAsync.AnonymousMethod__44_0((Azure.Messaging.ServiceBus.Amqp.AmqpReceiver, int maxMessages, System.TimeSpan? maxWaitTime) value, System.TimeSpan timeout, System.Threading.CancellationToken token) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.__Canon>.AsyncStateMachineBox<Azure.Messaging.ServiceBus.Amqp.AmqpReceiver.ExecutionContextCallback(object s) Unknown
System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Collections.Generic.IReadOnlyList<Azure.Messaging.ServiceBus.ServiceBusReceivedMessage>>.AsyncStateMachineBox<Azure.Messaging.ServiceBus.Amqp.AmqpReceiver.MoveNext(System.Threading.Thread threadPoolThread) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.__Canon>.AsyncStateMachineBox<Azure.Messaging.ServiceBus.Amqp.AmqpReceiver.MoveNext() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__12_0(System.Action innerContinuation, System.Threading.Tasks.Task innerTask) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action action, bool allowInlining) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishSlow(bool userDelegateExecute) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.TrySetException(object exceptionObject) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Collections.Generic.IReadOnlyList<Azure.Messaging.ServiceBus.ServiceBusReceivedMessage>>.SetException(System.Exception exception, ref System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<Azure.Messaging.ServiceBus.ServiceBusReceivedMessage>> taskField) Unknown
[Completed] Azure.Messaging.ServiceBus.dll!Azure.Messaging.ServiceBus.Amqp.AmqpReceiver.ReceiveMessagesAsyncInternal(int maxMessages, System.TimeSpan? maxWaitTime, System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.__Canon>.AsyncStateMachineBox<Azure.Messaging.ServiceBus.Amqp.AmqpReceiver.<ReceiveMessagesAsyncInternal>d__45>.ExecutionContextCallback(object s) Unknown
System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Collections.Generic.IReadOnlyList<Azure.Messaging.ServiceBus.ServiceBusReceivedMessage>>.AsyncStateMachineBox<Azure.Messaging.ServiceBus.Amqp.AmqpReceiver.<ReceiveMessagesAsyncInternal>d__45>.MoveNext(System.Threading.Thread threadPoolThread) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.__Canon>.AsyncStateMachineBox<Azure.Messaging.ServiceBus.Amqp.AmqpReceiver.<ReceiveMessagesAsyncInternal>d__45>.MoveNext() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__12_0(System.Action innerContinuation, System.Threading.Tasks.Task innerTask) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action action, bool allowInlining) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.FinishSlow(bool userDelegateExecute) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.TrySetException(object exceptionObject) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<Microsoft.Azure.Amqp.ReceivingAmqpLink>.SetException(System.Exception exception, ref System.Threading.Tasks.Task<Microsoft.Azure.Amqp.ReceivingAmqpLink> taskField) Unknown
[Completed] Microsoft.Azure.Amqp.dll!Microsoft.Azure.Amqp.Singleton<Microsoft.Azure.Amqp.ReceivingAmqpLink>.GetOrCreateAsync(System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<Microsoft.Azure.Amqp.ReceivingAmqpLink>.AsyncStateMachineBox<Microsoft.Azure.Amqp.Singleton<Microsoft.Azure.Amqp.ReceivingAmqpLink>.<GetOrCreateAsync>d__24>.ExecutionContextCallback(object s) Unknown
System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<Microsoft.Azure.Amqp.ReceivingAmqpLink>.AsyncStateMachineBox<Microsoft.Azure.Amqp.Singleton<Microsoft.Azure.Amqp.ReceivingAmqpLink>.<GetOrCreateAsync>d__24>.MoveNext(System.Threading.Thread threadPoolThread) Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.__Canon>.AsyncStateMachineBox<Microsoft.Azure.Amqp.Singleton<System.__Canon>.<GetOrCreateAsync>d__24>.MoveNext() Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__12_0(System.Action innerContinuation, System.Threading.Tasks.Task innerTask) Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.System.Threading.IThreadPoolWorkItem.Execute() Unknown
System.Private.CoreLib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() Unknown
System.Private.CoreLib.dll!System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() Unknown
[Async Call Stack]
[Async] Azure.Messaging.ServiceBus.dll!Azure.Messaging.ServiceBus.ServiceBusProcessor.ReceiveAndProcessMessagesAsync(Azure.Messaging.ServiceBus.ReceiverManager receiverManager, System.Threading.CancellationToken cancellationToken) Unknown
[Async] System.Private.CoreLib.dll!System.Threading.Tasks.Task.WhenAll Unknown
[Async] Azure.Messaging.ServiceBus.dll!Azure.Messaging.ServiceBus.ServiceBusProcessor.RunReceiveTaskAsync(System.Threading.CancellationToken cancellationToken) Unknown
[Async] Azure.Messaging.ServiceBus.dll!Azure.Messaging.ServiceBus.ServiceBusProcessor.StopProcessingAsync(System.Threading.CancellationToken cancellationToken) Unknown
[Async] Azure.Messaging.ServiceBus.dll!Azure.Messaging.ServiceBus.ServiceBusProcessor.CloseAsync(System.Threading.CancellationToken cancellationToken) Unknown
As a small addition we have build a minimal reproducible example:
In this case error handler is called when closing serviceBusProcessor.
The topic topicName has already been deleted via another microservice. And we want to properly close serviceBusProcessor in this microservice.
using Azure.Messaging.ServiceBus;
using Azure.Messaging.ServiceBus.Administration;
const string topicName = "topicName";
const string subName = "subscriptionName";
const string connectionString = "<your_connection_string>";
var serviceBusAdministrationClient = new ServiceBusAdministrationClient(connectionString);
await serviceBusAdministrationClient.CreateTopicAsync(new CreateTopicOptions(topicName)).ConfigureAwait(false);
await serviceBusAdministrationClient.CreateSubscriptionAsync(new CreateSubscriptionOptions(topicName, subName)).ConfigureAwait(false);
var serviceBusClient = new ServiceBusClient(connectionString,
new ServiceBusClientOptions { TransportType = ServiceBusTransportType.AmqpWebSockets });
var serviceBusProcessor =
serviceBusClient.CreateProcessor(topicName, subName);
serviceBusProcessor.ProcessMessageAsync += _ => Task.CompletedTask;
serviceBusProcessor.ProcessErrorAsync += (args) =>
{
Console.WriteLine($"ERROR HANDLER CALLED, {args.Exception}");
return Task.CompletedTask;
};
await serviceBusProcessor.StartProcessingAsync();
// Called in another microservice
await serviceBusAdministrationClient.DeleteTopicAsync(topicName);
await serviceBusProcessor.CloseAsync();
I can confirm this stack trace and the minimal example from @kprses1, can you please take a look at them?
@exciting-prism, @kprses1: Thanks for the additional context. In this scenario, you're deleting the topic while the processor is running. That's not something that we'd recommend doing. The error is normal and expected.
To avoid it, you should be stopping the processor before deleting the topic. When the topic is deleted, the existing AMQP link to the associated subscription used by the processor is force-closed by the service. When you call to stop the processor in this scenario, you're in a race condition. If the processor is able to stop before error recovery attempts to recreate the link, there is no exception. If the processor attempts to recreate the link before stopping and the subscription is already gone, then you'll correctly see this error.
Hi @exciting-prism. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.
/unresolve Thank you for your response!
In our case we have two or more processes. Process A is the creator, owner and deleter of the topic. Process B is subscribed to that topic. When we want to delete the topic, process A sends an event on a second channel, so process B can try to close the connection to the topic. Some time after sending the event process A deletes the topic. Most of the time process A is faster than process B, which results in this exception.
Do you have any recommendation on how to change that?
Is there a way to check if an topic has been deleted without throwing an Exception?
Or would it be possible to add a TryCloseAsync()-function which doesn't throw an exception if the topic doesn't exist?
@exciting-prism: At the end of the day, if you want to avoid this exception you must stop your processor before deleting the topic. As stated, we do not advise that you delete entities while they are still in use.
If it were me, I'd look to have my application signal that it would like to delete the topic as you're doing but take no further action until the other processes acknowledge that they have closed their readers. The topic is not deleted until the other nodes have acknowledged that they have completed their shut down procedure. There's no variant of this where simply guessing at the timing is 100% safe.
Unfortunately, as this is outside the scope of the Azure SDK package and is something related to your application domain, we're unable to provide further assistance for the scenario.
Or would it be possible to add a TryCloseAsync()-function which doesn't throw an exception if the topic doesn't exist?
Thank you for the suggestion, but this is not a feature that we would consider adding. From the library's perspective, you've asked it to read from a subscription that does not exist, which is a legitimate problem. You could add this as an extension method in your application that does a try/catch around the processor's StopProcessingAsync and ignores exceptions, if that is something that you feel is desirable in your specific scenario.
Hi @exciting-prism. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.
Hi @exciting-prism, since you haven’t asked that we /unresolve the issue, we’ll close this out. If you believe further discussion is needed, please add a comment /unresolve to reopen the issue.