Azure Function(服务总线触发器)System.OperationCanceledException

pdsfdshx  于 2023-04-22  发布在  其他
关注(0)|答案(1)|浏览(112)

我有一个Azure函数(.net 6.0),它从服务总线接收消息。99%的消息处理得很好,但我偶尔会在Application Insights中收到System.OperationCanceledException。
调用堆栈:

System.OperationCanceledException:
   at Microsoft.Azure.WebJobs.ServiceBus.MessageProcessor.CompleteProcessingMessageAsync (Microsoft.Azure.WebJobs.Extensions.ServiceBus, Version=5.5.1.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)
   at Microsoft.Azure.WebJobs.ServiceBus.Listeners.ServiceBusListener+<ProcessMessageAsync>d__26.MoveNext (Microsoft.Azure.WebJobs.Extensions.ServiceBus, Version=5.5.1.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at Azure.Messaging.ServiceBus.ServiceBusProcessor+<OnProcessMessageAsync>d__104.MoveNext (Azure.Messaging.ServiceBus, Version=7.8.1.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at Azure.Messaging.ServiceBus.ReceiverManager+<OnMessageHandler>d__19.MoveNext (Azure.Messaging.ServiceBus, Version=7.8.1.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
   at Azure.Messaging.ServiceBus.ReceiverManager+<ProcessOneMessage>d__15.MoveNext (Azure.Messaging.ServiceBus, Version=7.8.1.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)

调用堆栈(只是我的代码):

System.OperationCanceledException
Microsoft.Azure.WebJobs.ServiceBus.MessageProcessor.CompleteProcessingMessageAsync
[external code]
Azure.Messaging.ServiceBus.ServiceBusProcessor+<OnProcessMessageAsync>d__104.MoveNext
[external code]
Azure.Messaging.ServiceBus.ReceiverManager+<OnMessageHandler>d__19.MoveNext
[external code]
Azure.Messaging.ServiceBus.ReceiverManager+<ProcessOneMessage>d__15.MoveNext

查看FormattedMessage:它似乎在ProcessMessageCallback上失败了。我查了一下,我能找到的唯一信息是:从传递给订阅的用户processMessage回调中抛出的错误。
失败的方法是:Azure.Messaging.ServiceBus.ServiceBusProcessor+d__104.MoveNext
对我来说,这看起来像是一个服务总线问题,而不是我的代码。我使用的是Microsoft.Azure.WebJobs.Extensions.ServiceBus v5.5.1。
有没有人遇到过这个问题,或者知道如何解决这个问题?
更新:我添加了异常处理,希望能捕获更多信息:

catch (OperationCanceledException ex)
    {
        throw new OperationCanceledException(ex.Message);
    }
    catch (Exception ex)
    {
        throw new ApplicationException(ex.Message);
    }
2izufjch

2izufjch1#

当函数主机尝试停止或回收示例时,例如在扩展期间,可能会发生这种情况。如果函数正在3个示例上运行,并且正在扩展到2个示例上运行,则被“杀死”的示例将被取消。

相关问题