Azure-webjobs-sdk: Service Bus Queue messages lock not auto renewing

Created on 25 Jan 2017  路  6Comments  路  Source: Azure/azure-webjobs-sdk

It seems that messages on a Service Bus Queue are not getting the lock auto renewed.

I've tried AutoRenewTimeout on the MessageOptions and tried using OnMessageReceived which is supposed to auto renew. But when testing in a console app it does not auto renew, the lock is lost and the message is processed again.

I've been testing a with a short delay to mimic a long running task. I've tried the latest beta versions 2.0.0 and v1.1.2 both have the same behaviour.

static void Main()
        {            
            var config = new JobHostConfiguration(_azureWebJobsDashboard);

            ServiceBusConfiguration sbc = new ServiceBusConfiguration();           
            sbc.MessageOptions.AutoRenewTimeout = TimeSpan.FromSeconds(20);     

            config.UseServiceBus(sbc);            

            var host = new JobHost(config);                 
            host.RunAndBlock();
        }

public async static Task ProcessQueueMessage([ServiceBusTrigger("queue")] BrokeredMessage message, TextWriter log)
        {
            Console.WriteLine("Message received.");
            Thread.Sleep(12 * 1000); // 12 seconds, lock is set to 10 seconds
            Console.WriteLine("Message Complete.");
        }

The only way I've been able to get the lock to renew is by adding a timer to renew it as mentioned on this post:
http://stackoverflow.com/questions/27953882/guidance-onmessageoptions-autorenewtimeout

I found the azure sample also had the same behaviour I am experiencing.

All 6 comments

Does this happen every time you run your app?

I just tried your code exactly in a new project and it worked as expected for me -- I even turned the AutoRenewTimeout up to 60 seconds and had the sleep be 55 seconds (with the lock duration on the queue still set at 10).

Yes every time, I'm running locally could that be why?

Well after lots of reading and debugging I've finally found the issue.

It was the Time on my pc. I decided to do a test by setting the Time on my pc to UTC Coordinated Universal Time (it was initially set to UTC +00:00 London) and the locks successfully automatically renewed!

I then set the time back to UTC London and it continued to work. It stops working again if I manually adjust the time to be incorrect by a minute or so.

So I would assume that the time on my pc was out slightly

I'm running locally as well, so there shouldn't be anything inherently wrong with that.

I'm trying to brainstorm why you could see that but can't really think of anything. Some random ideas that may get us closer to understanding this:

  • What if you used await Task.Delay(12 * 1000); instead of the Sleep?
  • Have you tried running this in Azure?
  • Can you share the whole packages.config for your project?

Our posts just overlapped -- wow, that's crazy, nice debugging! So others have bumped into this as well?

Anyway, I'm glad you're unblocked.

Perhaps yes, a comment on this thread about Clock Drift gave me the idea to check the time
http://stackoverflow.com/questions/21433482/why-does-brokeredmessage-renewlock-only-renew-the-lock-for-a-few-seconds

Anyway, thanks for your help.

Was this page helpful?
0 / 5 - 0 ratings