3

I have a console application registered to azure service bus that sometimes (not periodically, but random) show me the following error:

The operation did not complete within the allotted timeout of 00:00:20. The time allotted to this operation may have been a portion of a longer timeout

And the following stack trace:

8-08-18 05:55:13.1251|ERROR|TestCefBrowserConsole.Workers.LinkWorkerThread|The operation did not complete within the allotted timeout of 00:00:20. The time allotted to this operation may have been a portion of a longer timeout. For more information on exception types and proper exception handling, please refer to http://go.microsoft.com/fwlink/?LinkId=761101   at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageReceiver.EndUpdateCommand(IAsyncResult result)
   at Microsoft.ServiceBus.Messaging.BatchManager`1.PerformFlushAsyncResult.OnFlushCompleted(IAsyncResult result, IList`1 batchedObjectsAsyncResults)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at Microsoft.ServiceBus.Messaging.BatchManager`1.EndFlush(IAsyncResult result)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at Microsoft.ServiceBus.Messaging.BatchManager`1.EndBatchedOperation(IAsyncResult result)
   at Microsoft.ServiceBus.Messaging.BatchManagerAsyncResult`1.OnBatchedCallback(IAsyncResult result)
   at Microsoft.ServiceBus.Common.AsyncResult.AsyncCompletionWrapperCallback(IAsyncResult result)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageReceiver.OnEndComplete(IAsyncResult result)
   at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at Microsoft.ServiceBus.Messaging.ReceiveContext.EndComplete(IAsyncResult result)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at TestCefBrowserConsole.Workers.LinkWorkerThread.<<ListenOnQueueChange>b__5_1>d.MoveNext() in D:\Progetti\UrlTracker\TraceyClient\TestCefBrowserConsole\Workers\LinkWorkerThread.cs:line 76 

And this stack trace is shown almost 20 times in the period of 1 minute (I'm using NLog to log error on text file)

As you can see the last time in the stack trace suggest to check line 76 in LinkWorkerThread.cs. Here it is the code:

client.OnMessageAsync(async message =>
    {
        Console.ForegroundColor = ConsoleColor.Red;
        Console.WriteLine("message from api");
        if (message.DeliveryCount > 2)
        {
            MaxDeliveryCountReached(message);
            await message.DeadLetterAsync();
         }
         else
         {
            try
            {
                await ProcessServiceBusMessage(message);
                await message.CompleteAsync();
            }
            catch (Exception ex)
            {
                errLog.Error(ex.Message + ex.StackTrace);
                await message.DeadLetterAsync();
            }
         }
    }, new OnMessageOptions() { AutoComplete = false, MaxConcurrentCalls = 20, AutoRenewTimeout = new TimeSpan(0, 5, 0) });  

Line 76 is await message.CompleteAsync().

Why does the allotted timeout exception occur? How can I solve that? Thank you

0 Answers0