У меня следующая ситуация:
У меня есть рабочая роль, развернутая в Azure, которая используется для чтения сообщений из служебной шины Azure. Я также подключил его к сервису Application Insights, чтобы отслеживать трассировки и исключения. Очень упрощенный алгоритм в рабочей роли:
while(true)
{
queueClient = new QueueClient();
try
{
while(true)
{
queueClient.Receive();
{
}
catch
{
queueClient.Dispose();
}
}
Проблема, которая иногда возникает в какое-то случайное время, когда не происходит обработка, заключается в том, что метод QueClient Receive () завершается неудачно и выдает исключение со следующей трассировкой:
Microsoft.ServiceBus.Messaging.MessagingException:
at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageReceiver.EndReceiveCommand (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
at Microsoft.ServiceBus.Common.AsyncResult.End (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageReceiver.OnEndTryReceive (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Microsoft.ServiceBus.Messaging.MessageReceiver+RetryReceiveAsyncResult+<>c.<GetAsyncSteps>b__15_3 (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
at Microsoft.ServiceBus.Common.AsyncResult.End (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Microsoft.ServiceBus.Messaging.MessageReceiver.OnTryReceive (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Microsoft.ServiceBus.Messaging.MessageReceiver.TryReceive (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Microsoft.ServiceBus.Messaging.MessageReceiver.TryReceive (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Microsoft.ServiceBus.Messaging.QueueClient.Receive (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Novolyze.VOD.AzureServiceBusQueuing.ServiceBusQueue`1.Receive (Novolyze.VOD.AzureServiceBusQueuing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullNovolyze.VOD.AzureServiceBusQueuing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: D:\Development\Projects\Novolyze\Source\Novolyze.VOD.AzureServiceBusQueuing\ServiceBusQueue.csNovolyze.VOD.AzureServiceBusQueuing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: 67)
at Novolyze.VOD.AzureServiceBusQueuing.ServiceBusQueue`1.Novolyze.VOD.ServiceBusQueuingInterface.IServiceBusQueue.Receive (Novolyze.VOD.AzureServiceBusQueuing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullNovolyze.VOD.AzureServiceBusQueuing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: D:\Development\Projects\Novolyze\Source\Novolyze.VOD.AzureServiceBusQueuing\ServiceBusQueue.csNovolyze.VOD.AzureServiceBusQueuing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: 118)
at Novolyze.VOD.WorkerRoleWithSBQueue.WorkerRole+<>c__DisplayClass7_0.<OnStart>b__0 (Novolyze.VOD.WorkerRoleWithSBQueue, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullNovolyze.VOD.WorkerRoleWithSBQueue, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: D:\Development\Projects\Novolyze\Source\Novolyze.VOD.WorkerRoleWithSBQueue\WorkerRole.csNovolyze.VOD.WorkerRoleWithSBQueue, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: 108)
Inner exception System.ServiceModel.FaultException`1[[System.ServiceModel.ExceptionDetail, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] handled at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageReceiver.EndReceiveCommand:
at Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement+DuplexRequestSessionChannel.ThrowIfFaultMessage (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement+DuplexRequestSessionChannel.HandleMessageReceived (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
at Microsoft.ServiceBus.Common.AsyncResult.End (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement+DuplexRequestSessionChannel.EndRequest (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement+ReconnectChannelFactory`1+RequestSessionChannel+RequestAsyncResult+<>c.<GetAsyncSteps>b__9_3 (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
at Microsoft.ServiceBus.Common.AsyncResult.End (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement+ReconnectChannelFactory`1+RequestSessionChannel.EndRequest (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Microsoft.ServiceBus.Messaging.Sbmp.RedirectBindingElement+RedirectContainerChannelFactory`1+RedirectContainerSessionChannel+RequestAsyncResult+<>c__DisplayClass8_1.<GetAsyncSteps>b__4 (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
at Microsoft.ServiceBus.Common.AsyncResult.End (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Microsoft.ServiceBus.Messaging.Sbmp.RedirectBindingElement+RedirectContainerChannelFactory`1+RedirectContainerSessionChannel.EndRequest (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement+ReconnectChannelFactory`1+RequestSessionChannel+RequestAsyncResult+<>c.<GetAsyncSteps>b__9_3 (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)
at Microsoft.ServiceBus.Common.AsyncResult.End (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement+ReconnectChannelFactory`1+RequestSessionChannel.EndRequest (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageReceiver.EndReceiveCommand (Microsoft.ServiceBus, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
Я улавливаю исключение, записываю его в Application Insights и через 20 секунд после сбоя этой рабочей роли. Я обнаружил, что возникает еще одно необработанное исключение, которое является исключением Timeout при попытке избавиться от QueueClient, что происходит после сбоев Receive (). Вот трассировка стека:
<Event xmlns='http://schemas.microsoft.com/win/2004/08/events/event'><System><Provider Name='Windows Azure Runtime 2.7.0.0'/><EventID Qualifiers='49152'>2001</EventID><Level>2</Level><Task>1</Task><Keywords>0x80000000000000</Keywords><TimeCreated SystemTime='2018-08-23T00:53:36.988460700Z'/><EventRecordID>39</EventRecordID><Channel>Windows Azure</Channel><Computer>RD0003FF1F0254</Computer><Security/></System><EventData><Data>System.TimeoutException</Data><Data>Process ID: 2616
Process Name: WaWorkerHost
Thread ID: 13
AppDomain Unhandled Exception for role Novolyze.VOD.WorkerRoleWithSBQueue_IN_0
Exception: 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.OnEndClose(IAsyncResult result)
at Microsoft.ServiceBus.Messaging.ClientEntity.EndClose(IAsyncResult result)
at Microsoft.ServiceBus.Messaging.CloseEntityCollectionAsyncResult.CompleteClose(ClientEntity entity, 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.MessageClientEntityManager.EndClose(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.Sbmp.SbmpQueueClient.CloseAsyncResult.<>c.<GetAsyncSteps>b__3_3(CloseAsyncResult thisPtr, IAsyncResult r)
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.Sbmp.SbmpQueueClient.OnEndClose(IAsyncResult result)
at Microsoft.ServiceBus.Messaging.ClientEntity.EndClose(IAsyncResult result)
at Microsoft.ServiceBus.Messaging.ClientEntity.Close(TimeSpan timeout)
at Novolyze.VOD.AzureServiceBusQueuing.ServiceBusQueue`1.Dispose(Boolean disposing) in D:\Development\Projects\Novolyze\Source\Novolyze.VOD.AzureServiceBusQueuing\ServiceBusQueue.cs:line 98
at Novolyze.VOD.WorkerRoleWithSBQueue.WorkerRole.<>c__DisplayClass7_0.<OnStart>b__0() in D:\Development\Projects\Novolyze\Source\Novolyze.VOD.WorkerRoleWithSBQueue\WorkerRole.cs:line 142
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Inner Exception: 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.DuplexRequestBindingElement.DuplexRequestSessionChannel.ThrowIfFaultMessage(Message wcfMessage)
at Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement.DuplexRequestSessionChannel.HandleMessageReceived(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.DuplexRequestBindingElement.DuplexRequestSessionChannel.EndRequest(IAsyncResult result)
at Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement.ReconnectChannelFactory`1.RequestSessionChannel.RequestAsyncResult.<>c.<GetAsyncSteps>b__9_3(RequestAsyncResult thisPtr, IAsyncResult r)
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.Channels.ReconnectBindingElement.ReconnectChannelFactory`1.RequestSessionChannel.EndRequest(IAsyncResult result)
at Microsoft.ServiceBus.Messaging.Sbmp.RedirectBindingElement.RedirectContainerChannelFactory`1.RedirectContainerSessionChannel.RequestAsyncResult.<>c__DisplayClass8_1.<GetAsyncSteps>b__4(RequestAsyncResult thisPtr, IAsyncResult r)
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.Sbmp.RedirectBindingElement.RedirectContainerChannelFactory`1.RedirectContainerSessionChannel.EndRequest(IAsyncResult result)
at Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement.ReconnectChannelFactory`1.RequestSessionChannel.RequestAsyncResult.<>c.<GetAsyncSteps>b__9_3(RequestAsyncResult thisPtr, IAsyncResult r)
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.Channels.ReconnectBindingElement.ReconnectChannelFactory`1.RequestSessionChannel.EndRequest(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.Sbmp.SbmpMessageReceiver.AbandonPrefetchedMessagesCloseAbortAsyncResult.<>c.<GetAsyncSteps>b__2_3(AbandonPrefetchedMessagesCloseAbortAsyncResult thisPtr, IAsyncResult r)
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.Sbmp.SbmpMessageReceiver.OnEndClose(IAsyncResult result)
</Data></EventData></Event>
Поскольку у меня нет платного плана поддержки для технических инженеров из Azure, у кого-нибудь есть идея:
- Почему возникают такие исключения (возможно, экземпляр служебной шины неработоспособен или что-то в моем коде отсутствует)?
- Если я заверну удаление в try catch и исключу исключение из-за сбоя утилизации, могу ли я быть уверен, что QueueClient будет собирать мусор и что у меня не возникнет проблем, чтобы просто создать новый экземпляр?