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] Many abandoned messages in queues/topics

See original GitHub issue

Description Recently we migrated from WindowsAzure.ServiceBus to Azure.Messaging.ServiceBus. After deployment to production we noticed that processing of messages is slow down and there are many abandoned messages in queue/topics.

There is screenshot of metrics before deployment (WindowsAzure.ServiceBus): image

And there is screenshot of current state (Azure.Messaging.ServiceBus): image

We investigated the issue and found:

  1. We do not abandon messages in code, it happens inside of Azure.Messaging.ServiceBus
  2. Topics and queues are affected
  3. We have the issue only if ServiceBusReceiverOptions.PrefetchCount is not defined.

Expected behavior No abandoned messages if we do not abandon them directly in code.

Actual behavior (include Exception or Stack Trace) Lot’s of abandoned massages came from the library.

To Reproduce I was able to reproduce the problem in console application:

	class Program
	{
		static void Main(string[] args)
		{
			var receiver = new Receiver4();
			receiver.ReadMessages().GetAwaiter().GetResult();			
		}
	}

    class Receiver4
    {
        private const string ConnectionString = "connection string";

        public async Task ReadMessages()
        {
            var sbOptions = new ServiceBusClientOptions()
            {
                RetryOptions = new ServiceBusRetryOptions
                {
                    Mode = ServiceBusRetryMode.Fixed,
                    Delay = TimeSpan.FromSeconds(1),
                    MaxDelay = TimeSpan.FromSeconds(5),
                    MaxRetries = 1,
                    TryTimeout = TimeSpan.FromSeconds(30)
                }
            };

            ServiceBusClient client = new ServiceBusClient(ConnectionString, sbOptions);

            ServiceBusReceiverOptions options = new ServiceBusReceiverOptions
            {
            };

            var receiver = client.CreateReceiver("alex-test", options);

            var receivedMessages = new List<ServiceBusReceivedMessage>();
            while (true)
            {
                Console.WriteLine("Reading");

                var messages = await receiver.ReceiveMessagesAsync(128, TimeSpan.FromSeconds(5)).ConfigureAwait(false);

                Console.WriteLine($"{messages.Count} were received");

                foreach (var message in messages)
                {
                    Console.WriteLine(message.Body.ToString());

                    receivedMessages.Add(message);
                }

                await Task.Delay(100);

                Console.WriteLine("Completing");

                foreach (var message in receivedMessages)
                {
                    try
                    {
                        await receiver.CompleteMessageAsync(message).ConfigureAwait(false);
                    }
                    catch (ServiceBusException ex) when (ex.Reason == ServiceBusFailureReason.MessageLockLost)
                    {
                        Console.WriteLine("MessageLockLost, {0}", message.Body.ToString());
                    }
                }

                receivedMessages.Clear();

                Console.WriteLine("Completed");

                ConsoleKeyInfo key = Console.ReadKey();

                if (key.KeyChar == 's')
                {
                    break;
                }
            }
        }
    }

Environment:

  • Name and version of the Library package used: Azure.Messaging.ServiceBus 7.3.0
  • Hosting platform or OS and .NET runtime version Azure Cloud Services
  • IDE and version : Visual Studio 16.11.4

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:18 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
JoshLove-msftcommented, Oct 15, 2021

Thanks, I was able to repro and am seeing the same behavior. I have reached out to the service team to find out more about this metric.

0reactions
Alex-Boocommented, Nov 10, 2021

Unlock is a variation of abandon, and our metrics are reporting that operation as abandon. We will fix it in the service. It is not a client issue.

@yvgopal, thank you for explanation. Can we track somehow fixing this issue on server side?

Read more comments on GitHub >

github_iconTop Results From Across the Web

[BUG] Stopping ServiceBusProcessor causes some ...
Once processor is stopped/disposed it lefts often some messages locked in the queue. It seems caused by TaskCanceledException thrown in AmqpReceiver.
Read more >
Best practices for improving performance using Azure ...
This article describes how to use Azure Service Bus to optimize performance when exchanging brokered messages. The first part of this ...
Read more >
Calling Abandon on an Azure Service Bus re-queues the ...
I start receiving and get message with sequence 1, as expected. If I then abandon this message using message.Abandon (the reason for abandoning...
Read more >
QueueExplorer History
Importing multiple message bodies now doesn't open dialog for each message. Fixed bug with grouping when there are two queues with the same...
Read more >
Everything You Need to Know About Azure Service Bus ...
But as far as message handling by our receiver, we will need to complete, abandon or dead-letter the message. We'll talk more about...
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