[BUG] Azure.Messaging.ServiceBus.ServiceBusException: 'sender179' is closed (GeneralError)
See original GitHub issueLibrary name and version
Azure.Messaging.ServiceBus 7.3.0
Describe the bug
Hi, occasionally I am this error(sender number changes during the time):
_Azure.Messaging.ServiceBus.ServiceBusException: 'sender179' is closed (GeneralError)
at Azure.Messaging.ServiceBus.Amqp.AmqpSender.SendBatchInternalAsync(IEnumerable`1 messages, TimeSpan timeout, CancellationToken cancellationToken)
at Azure.Messaging.ServiceBus.Amqp.AmqpSender.<>c.<<SendBatchAsync>b__18_0>d.MoveNext()
--- End of stack trace from previous location ---
at Azure.Messaging.ServiceBus.ServiceBusRetryPolicy.<>c__20`1.<<RunOperation>b__20_0>d.MoveNext()
--- End of stack trace from previous location ---
at Azure.Messaging.ServiceBus.ServiceBusRetryPolicy.RunOperation[T1,TResult](Func`4 operation, T1 t1, TransportConnectionScope scope, CancellationToken cancellationToken)
at Azure.Messaging.ServiceBus.ServiceBusRetryPolicy.RunOperation[T1,TResult](Func`4 operation, T1 t1, TransportConnectionScope scope, CancellationToken cancellationToken)
at Azure.Messaging.ServiceBus.ServiceBusRetryPolicy.RunOperation[T1](Func`4 operation, T1 t1, TransportConnectionScope scope, CancellationToken cancellationToken)
at Azure.Messaging.ServiceBus.Amqp.AmqpSender.SendBatchAsync(ServiceBusMessageBatch messageBatch, CancellationToken cancellationToken)
at Azure.Messaging.ServiceBus.ServiceBusSender.SendMessagesAsync(ServiceBusMessageBatch messageBatch, CancellationToken cancellationToken)_
My code:
public async Task PublishAsync(IDomainEventBase<IEventData> domainEventBase)
{
var eventName = domainEventBase.GetType().Name;
var sender = GetOrCreateSender(eventName);
var serializedEvent = SerializeObject(domainEventBase);
var message = new ServiceBusMessage(serializedEvent)
{
Subject = domainEventBase.EventType
};
await sender.SendMessageAsync(message);
_telemetryClientService.TrackEvent(domainEventBase.Data.ToDictionary(), eventName);
}
I have contacted the Azure Service support but it didn’t provide me any details. The only suggestion was implementing retry and a link to msdn doc.
However, how should I implement retry? I am using the default retry option so it should be retried by default. I see that these failures are happening very shortly and quite rarely but at that moment all my service bus’s “Send” operations fails. Can there be an issue on Service Bus side? But then how can I rely on ServiceBus while it has a shortage every two days. At the moment Service Bus Send operations are quite critical for my application so it would be nice to resolve this kind of issues.
Expected behavior
Service bus events should be published.
Actual behavior
Service bus event is not published.
Reproduction Steps
These error are seemed in Application Insights
Environment
Asp.Net Core 5
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top GitHub Comments
Apology for interrupting, but I would suggest to add (in your factory) check for sender.IsCLosed() before returning it. If closed then create a new one.
Apology again, but as this is about sender and factory I would ask dear Coders about that missing factory in ASB ServiceClient? The built in DI method for adding an AzureServiceBus client factory doesn’t internally track senders. It seems an oversight on Microsoft’s part that you can use it to track clients (using a key, much like you have) but when you ask the client for a sender, you just get a new one every time. This seems to violate MS’s own best practice guide? Net core 3.1, Azure.Messaging.ServiceBus 7.1.2
Thank you.
@LeszekKalibrate thank you