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] Azure.Messaging.ServiceBus.ServiceBusException: 'sender179' is closed (GeneralError)

See original GitHub issue

Library 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
LeszekKalibratecommented, Jan 20, 2022

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.

0reactions
deivyd321commented, Feb 24, 2022

@LeszekKalibrate thank you

Read more comments on GitHub >

github_iconTop Results From Across the Web

Microsoft.Azure.ServiceBus.ServiceBusException: 'sender9 ...
This application continuously listen to queue on one service bus. ... ServiceBusException: 'sender179' is closed (GeneralError) at Azure.
Read more >
Azure.Messaging.ServiceBus.ServiceBusException
I am new to Azure Service Bus and appreciate any help I can get. ... ServiceBus.ServiceBusException: 'receiver31' is closed (GeneralError).
Read more >
Troubleshoot AMQP errors in Azure Service Bus
Link is closed. You see the following error when the AMQP connection and link are active but no calls (for example, send or...
Read more >
Azure Service Bus Connection issue - Microsoft Q&A
One of the test there is sending a message to azure service bus. The problem is when calling topicClient sendasyc it is getting...
Read more >
ServiceBusError class
GeneralError : The exception was the result of a general error within the client library. MessagingEntityNotFound: A Service Bus resource cannot be found...
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