【问题标题】:How to recover from Azure Cosmos DB Outage in Azure Function with Cosmos DB Trigger如何使用 Cosmos DB 触发器从 Azure 函数中的 Azure Cosmos DB 中断中恢复
【发布时间】:2019-01-04 12:33:25
【问题描述】:

带有 Cosmos DB 触发器的 Azure 函数 (v1) 如何从 Cosmos DB 中断中恢复? 这应该自动发生还是需要重新启动 Function App?

在我们的场景中,Cosmos DB 不可用,因为已达到订阅支出限制。取消支出限制后,Cosmos DB 再次可用,并且通过输出绑定写入 Cosmos DB 的函数成功。

通过 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 ---

重新启动 Function App 后,Cosmos DB 触发器再次工作。

我想,当 Cosmos DB 因其他原因出现中断时,也可能发生这种情况。

为了使我们的系统能够抵御 Cosmos DB 的临时中断,我们如何才能让 CosmosDB 触发器恢复运行状态?如果出现错误,我们是否必须重新启动函数应用,或者有更好的方法吗?

【问题讨论】:

    标签: azure azure-functions azure-cosmosdb


    【解决方案1】:

    这是由于 Azure Functions 运行时和 Cosmos DB 触发器中的重试机制存在问题。

    运行时不断尝试重新初始化触发器,呈指数级后退,但在这种特定情况下(帐户超过支出限制)遇到了问题。这是在Github issue 中跟踪的。

    fix for this has been merged,应该包含在运行时的下一个版本中。

    修复完成后,当帐户再次可用时,您应该不需要重新启动 Function App。

    【讨论】:

      猜你喜欢
      • 2022-06-23
      • 1970-01-01
      • 2023-01-31
      • 1970-01-01
      • 1970-01-01
      • 2018-04-10
      • 1970-01-01
      • 2021-10-03
      • 1970-01-01
      相关资源
      最近更新 更多