带有ServiceBus的Azure功能:操作已取消

时间:2020-07-21 09:55:55

标签: azure azure-functions

我刚刚为Azure功能部署了一个更新:计时器或servicebus触发器具有不同的功能。最近几天我发现与ServiceBus相关的错误

Microsoft.Azure.ServiceBus.ServiceBusCommunicationException-操作已取消。

enter image description here

我不知道函数接收消息时是否正在发生这种情况?

函数定义如下

[FunctionName("createInvoiceListFromServiceBus")]
public async Task Run(
        [ServiceBusTrigger("invoice.requests.bulk", "requests", Connection = "AccountingServiceBusConnection")] 
        string myQueueItem,
        [ServiceBus("invoice.pdf.requests", Connection = "AccountingServiceBusConnection")] 
        IAsyncCollector<dynamic> pdfServiceBusRequests,
        [ServiceBus("invoice.paid.requests", Connection = "AccountingServiceBusConnection")] 
        IAsyncCollector<dynamic> paidServiceBusRequests)
    {
    }

这是我正在使用的软件包

<PackageReference Include="AzureExtensions.Swashbuckle" Version="3.2.2" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
<PackageReference Include="Microsoft.Azure.KeyVault.Core" Version="3.0.5" />
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.1.7" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="4.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="3.1.5" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.7" />
<PackageReference Include="Xero.Api.SDK.Core" Version="1.1.4" />

这里是完整的错误描述。

[
   {
      "parsedStack":[
         {
            "assembly":"Microsoft.Azure.ServiceBus, Version=4.1.1.0, Culture=neutral, PublicKeyToken=7e34167dcc6d6d8c",
            "method":"Microsoft.Azure.ServiceBus.Core.MessageReceiver+<OnReceiveAsync>d__86.MoveNext",
            "level":0,
            "line":0
         },
         {
            "assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
            "method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw",
            "level":1,
            "line":0
         },
         {
            "assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
            "method":"System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess",
            "level":2,
            "line":0
         },
         {
            "assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
            "method":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification",
            "level":3,
            "line":0
         },
         {
            "assembly":"Microsoft.Azure.ServiceBus, Version=4.1.1.0, Culture=neutral, PublicKeyToken=7e34167dcc6d6d8c",
            "method":"Microsoft.Azure.ServiceBus.Core.MessageReceiver+<>c__DisplayClass64_0+<<ReceiveAsync>b__0>d.MoveNext",
            "level":4,
            "line":0
         },
         {
            "assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
            "method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw",
            "level":5,
            "line":0
         },
         {
            "assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
            "method":"System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess",
            "level":6,
            "line":0
         },
         {
            "assembly":"Microsoft.Azure.ServiceBus, Version=4.1.1.0, Culture=neutral, PublicKeyToken=7e34167dcc6d6d8c",
            "method":"Microsoft.Azure.ServiceBus.RetryPolicy+<RunOperation>d__19.MoveNext",
            "level":7,
            "line":0
         },
         {
            "assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
            "method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw",
            "level":8,
            "line":0
         },
         {
            "assembly":"Microsoft.Azure.ServiceBus, Version=4.1.1.0, Culture=neutral, PublicKeyToken=7e34167dcc6d6d8c",
            "method":"Microsoft.Azure.ServiceBus.RetryPolicy+<RunOperation>d__19.MoveNext",
            "level":9,
            "line":0
         },
         {
            "assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
            "method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw",
            "level":10,
            "line":0
         },
         {
            "assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
            "method":"System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess",
            "level":11,
            "line":0
         },
         {
            "assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
            "method":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification",
            "level":12,
            "line":0
         },
         {
            "assembly":"Microsoft.Azure.ServiceBus, Version=4.1.1.0, Culture=neutral, PublicKeyToken=7e34167dcc6d6d8c",
            "method":"Microsoft.Azure.ServiceBus.Core.MessageReceiver+<ReceiveAsync>d__64.MoveNext",
            "level":13,
            "line":0
         },
         {
            "assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
            "method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw",
            "level":14,
            "line":0
         },
         {
            "assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
            "method":"System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess",
            "level":15,
            "line":0
         },
         {
            "assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
            "method":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification",
            "level":16,
            "line":0
         },
         {
            "assembly":"Microsoft.Azure.ServiceBus, Version=4.1.1.0, Culture=neutral, PublicKeyToken=7e34167dcc6d6d8c",
            "method":"Microsoft.Azure.ServiceBus.Core.MessageReceiver+<ReceiveAsync>d__62.MoveNext",
            "level":17,
            "line":0
         },
         {
            "assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
            "method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw",
            "level":18,
            "line":0
         },
         {
            "assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
            "method":"System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess",
            "level":19,
            "line":0
         },
         {
            "assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
            "method":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification",
            "level":20,
            "line":0
         },
         {
            "assembly":"Microsoft.Azure.ServiceBus, Version=4.1.1.0, Culture=neutral, PublicKeyToken=7e34167dcc6d6d8c",
            "method":"Microsoft.Azure.ServiceBus.MessageReceivePump+<<MessagePumpTaskAsync>b__11_0>d.MoveNext",
            "level":21,
            "line":0
         }
      ],
      "severityLevel":"Information",
      "outerId":"0",
      "message":"The operation was canceled.",
      "type":"Microsoft.Azure.ServiceBus.ServiceBusCommunicationException",
      "id":"65258033"
   },
   {
      "parsedStack":[
         {
            "assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
            "method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw",
            "level":0,
            "line":0
         },
         {
            "assembly":"Microsoft.Azure.Amqp, Version=2.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
            "method":"Microsoft.Azure.Amqp.AsyncResult.End",
            "level":1,
            "line":0
         },
         {
            "assembly":"Microsoft.Azure.Amqp, Version=2.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35",
            "method":"Microsoft.Azure.Amqp.ReceivingAmqpLink.EndReceiveMessages",
            "level":2,
            "line":0
         },
         {
            "assembly":"Microsoft.Azure.ServiceBus, Version=4.1.1.0, Culture=neutral, PublicKeyToken=7e34167dcc6d6d8c",
            "method":"Microsoft.Azure.ServiceBus.Core.MessageReceiver+<>c__DisplayClass86_0.<OnReceiveAsync>b__1",
            "level":3,
            "line":0
         },
         {
            "assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
            "method":"System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic",
            "level":4,
            "line":0
         },
         {
            "assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
            "method":"System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw",
            "level":5,
            "line":0
         },
         {
            "assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
            "method":"System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess",
            "level":6,
            "line":0
         },
         {
            "assembly":"System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
            "method":"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification",
            "level":7,
            "line":0
         },
         {
            "assembly":"Microsoft.Azure.ServiceBus, Version=4.1.1.0, Culture=neutral, PublicKeyToken=7e34167dcc6d6d8c",
            "method":"Microsoft.Azure.ServiceBus.Core.MessageReceiver+<OnReceiveAsync>d__86.MoveNext",
            "level":8,
            "line":0
         }
      ],
      "severityLevel":"Information",
      "outerId":"65258033",
      "message":"The operation was canceled.",
      "type":"System.OperationCanceledException",
      "id":"65736993"
   }
]

1 个答案:

答案 0 :(得分:1)

错误是暂时的吗?然后,很可能是应用程序与其依赖项之间的某种连接问题。错误The operation was canceled表示一个异步任务已被取消,或者很可能超时
https://www.asptricks.net/2019/10/task-cancellationtoken-net-c-example.html

要进行超时搜索...查看pasredStack似乎是使用Microsoft.Azure.ServiceBus.Core.MessageReceiver超时的代码。从主要的主要run()方法可以推断出使用AccountingServiceBusConnection的两个操作之一可能已超时。

为重现该错误,我建议尝试在同时负载测试以下基础资源:pdfServiceBusRequestspaidServiceBusRequests的同时尝试此操作

或者,您可以延长某些隐式超时时间。考虑一下这些服务。有什么可能会超时吗?我们使用的是http客户端还是sql客户端?这些客户端倾向于具有隐式的默认超时,可以在代码中覆盖这些超时。我建议搜寻任何引用来进行Web或数据库调用的客户端,并搜索将其超时扩展到最大,以缓解此问题。另一个选择可能是尝试捕获并处理这些System.OperationCanceledException正常情况。