我有一个注册到azure服务总线的控制台应用程序,有时(不是周期性的,而是随机的)向我显示以下错误:
操作未在指定的00:00:20超时内完成。分配给该操作的时间可能是较长超时的一部分
以及以下堆栈跟踪:
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
此堆栈跟踪在1分钟的时间内显示了将近20次(我正在使用NLog在文本文件上记录错误)
您可以看到堆栈跟踪中的最后一次建议检查LinkWorkerThread.cs中的第76行。这是代码:
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) });
第76行为await message.CompleteAsync()
。
为什么分配的超时异常发生?我该如何解决?谢谢