应用服务计划的 Azure 函数应用超时
Posted
技术标签:
【中文标题】应用服务计划的 Azure 函数应用超时【英文标题】:Azure function app timeout for app service plan 【发布时间】:2019-08-30 08:44:10 【问题描述】:我确实遵循https://docs.microsoft.com/da-dk/azure/azure-functions/functions-host-json#functiontimeout 中提到的指南,通过使用“functionTimeout”更新主机文件将应用服务计划中功能应用主机的默认超时时间从 30 分钟增加到 2 小时:“02:00:00”
在检查函数应用的事件查看器日志时,我可以看到超时限制仍然是 30m。添加错误信息以供参考,
<EventData>
<Data>Application: w3wp.exe
CoreCLR Version: 4.6.27317.7
Description: The process was terminated due to an unhandled exception.
Exception Info: Microsoft.Azure.WebJobs.Host.FunctionTimeoutException: Timeout value of 00:30:00 was exceeded by function: CreateRequestApplicationPostProcessor
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryHandleTimeoutAsync(Task invokeTask, CancellationToken shutdownToken, Boolean throwOnTimeout, CancellationToken timeoutToken, TimeSpan timeoutInterval, IFunctionInstance instance, Action onTimeout) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 631
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeAsync(IFunctionInvoker invoker, ParameterHelper parameterHelper, CancellationTokenSource timeoutTokenSource, CancellationTokenSource functionCancellationTokenSource, Boolean throwOnTimeout, TimeSpan timerInterval, IFunctionInstance instance) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 547
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstance instance, ParameterHelper parameterHelper, ILogger logger, CancellationTokenSource functionCancellationTokenSource) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 503
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstance instance, ParameterHelper parameterHelper, IFunctionOutputDefinition outputDefinition, ILogger logger, CancellationTokenSource functionCancellationTokenSource) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 439
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstance instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 249
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstance instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 293
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryExecuteAsync(IFunctionInstance functionInstance, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 89
at Microsoft.Azure.WebJobs.Host.Timers.WebJobsExceptionHandler.<>c__DisplayClass3_0.<OnUnhandledExceptionAsync>b__0() in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Timers\WebJobsExceptionHandler.cs:line 54
at System.Threading.Thread.ThreadMain_ThreadStart()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
</Data>
</EventData>
</Event>
感谢您在覆盖自定义超时值方面的帮助。
【问题讨论】:
您是否为Always on
启用了应用服务计划?
感谢您查看@JoeyCai。是的
【参考方案1】:
如果您在应用服务计划上运行,则应启用 始终开启 设置,以便您的函数应用正确运行。
即使启用了 Always On,单个函数的执行超时也由 host.json 项目文件中的 functionTimeout
设置控制。
更多详情可以参考article。
【讨论】:
我已经在一个应用服务计划中运行函数应用程序,并且在我最初的问题中提到,host.json 中的值 "functionTimeout": "02:00:00" 始终处于打开状态跨度> 你的函数重启了吗?【参考方案2】:您始终可以在函数级别使用属性 [Timeout("1:00:00")] 来覆盖默认超时
【讨论】:
以上是关于应用服务计划的 Azure 函数应用超时的主要内容,如果未能解决你的问题,请参考以下文章