简体   繁体   English

如何使用Cosmos DB触发器从Azure函数中的Azure Cosmos DB中断中恢复

[英]How to recover from Azure Cosmos DB Outage in Azure Function with Cosmos DB Trigger

How can a Azure Function (v1) with Cosmos DB Trigger recover from a Cosmos DB Outage? 带有Cosmos DB触发器的Azure函数(v1)如何从Cosmos DB中断中恢复? Should this happen automatically or is a Function App restart required? 这应该自动发生还是需要重启功能应用程序?

In our scenario, Cosmos DB was unavailable because the subscription spending limit was reached. 在我们的方案中,Cosmos DB不可用,因为达到了订阅支出限制。 After removing the spending limit, Cosmos DB was available again and Functions writing to Cosmos DB through Output Bindings succeeded. 取消支出限制后,Cosmos DB再次可用,并且通过输出绑定写入Cosmos DB的函数成功。

The function who was connected to Cosmos DB through a CosmosDB Trigger however didn't recover from this outage and constantly threw the following exception: 但是,通过CosmosDB触发器连接到Cosmos DB的函数无法从此中断中恢复,并不断抛出以下异常:

Microsoft.Azure.WebJobs.Host.Listeners.FunctionListenerException: The listener for function 'xxx' was unable to start. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Azure.Documents.ChangeFeedProcessor.ChangeFeedEventHost.<StartAsync>d__77.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Documents.ChangeFeedProcessor.ChangeFeedEventHost.<RegisterObserverFactoryAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.WebJobs.Extensions.DocumentDB.CosmosDBTriggerListener.<StartAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.WebJobs.Host.Listeners.FunctionListener.<StartAsync>d__14.MoveNext()
   --- End of inner exception stack trace ---

After restarting the Function App, the Cosmos DB Trigger was working again. 重新启动Function App之后,Cosmos DB触发器再次工作。

I suppose, this could situation could also happen when Cosmos DB suffers from outages for other reasons. 我想,当Cosmos DB由于其他原因遭受中断时,也会发生这种情况。

In order to make our system resilient against temporary outages of Cosmos DB, how can we get CosmosDB Triggers back to an operational state? 为了使我们的系统能够抵御Cosmos DB的临时中断,我们如何才能使CosmosDB触发器返回到操作状态? Do we have to restart the function app in case of errors or is there a better way to do so? 如果出现错误,我们是否必须重新启动功能应用程序?或者有更好的方法吗?

This is due to an issue with the retrying mechanism in the Azure Functions runtime and the Cosmos DB Trigger. 这是由于Azure Functions运行时和Cosmos DB触发器中的重试机制存在问题。

The runtime keeps trying to reinitialize the Trigger, exponentially backing-off, but it was running into an issue on this particular scenario (account over the spending limit). 运行时不断尝试重新初始化触发器,以指数方式退缩,但是在这种特定情况下(超出支出限额),它遇到了问题。 This was being tracked in a Github issue . Github问题对此进行了跟踪。

A fix for this has been merged and should be included in the next releases of the runtime. 对此修复程序已合并 ,应该包含在运行时的下一发行版中。

When the fix is in place, you should not need to restart the Function App when the account is available again. 修复程序到位后,如果该帐户再次可用,则无需重新启动Function App。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM