Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.13k stars 4.53k forks source link

[QUERY] Calling CloseAsync() or DisposeAsync() on ServiceBusProcessor throws exception with reason ServiceBusFailureReason.MessagingEntityNotFound #44704

Open exciting-prism opened 6 days ago

exciting-prism commented 6 days ago

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

github-actions[bot] commented 6 days ago

Thank you for your feedback. Tagging and routing to the team member best able to assist.

jsquire commented 6 days ago

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?

github-actions[bot] commented 6 days ago

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.

kprses1 commented 5 days ago

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
kprses1 commented 5 days ago

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();
exciting-prism commented 4 days ago

I can confirm this stack trace and the minimal example from @kprses1, can you please take a look at them?