如何增加 ASP.NET Core 2.0 API 的 Azure 应用服务超时

2024-01-27

我有一个 ASP.NET Core 2.0 API,正在部署到 Azure 应用服务。这一直工作得很好,直到最近我不得不处理一个需要超过 2 分钟才能完成的请求,并且我得到了 502 Bad Gateway 说明

"The specified CGI application encountered an error and the server terminated the process". 

当我在这个过程中达到 2 分钟时,这种情况就会持续发生。

我的诊断日志文件说

018-05-25 02:07:01.462 +00:00 [Error] Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware: An unhandled exception has occurred while executing the request
System.Threading.Tasks.TaskCanceledException: A task was canceled.

我正在假设这是一个超时问题,因为它始终处于 2 分钟标记,并且我知道该请求需要 2 分钟以上才能完成。因此,我正在研究如何增加超时,并在 SO 上找到了一些帖子,其中讨论了使用 applicationHost.xdt 文件,将其放置在站点的 Site 文件夹的根目录中。我正在使用这个 XML;

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.applicationHost>
    <webLimits xdt:Transform="SetAttributes(connectionTimeout)" connectionTimeout="00:05:00" />
  </system.applicationHost>
</configuration>

当我使用 Kudu 调试控制台将其上传到我用来测试 API 的部署槽的站点文件夹的根目录,然后查看转换文件时,我看到以下内容:

2018-05-24T19:34:19 Start 'site' site extension transform
2018-05-24T19:34:19 StartSection Executing SetAttributes (transform line 4, 16)
2018-05-24T19:34:19 on /configuration/system.applicationHost/webLimits
2018-05-24T19:34:19 Applying to 'webLimits' element (no source line info)
2018-05-24T19:34:19 Set 'connectionTimeout' attribute
2018-05-24T19:34:19 Set 1 attributes
2018-05-24T19:34:19 EndSection Done executing SetAttributes
2018-05-24T19:34:19 Successful 'D:\home\site\applicationHost.xdt' site extension transform

在我看来,它成功地应用了 XDT 变换。

但是,即使在重新启动基础应用服务和相关部署槽之后也是如此。我仍然收到错误。

那么,我是否使用了错误的超时设置?

当我查看插槽站点/wwwroot 文件夹中的 web.config 文件时,它仅包含此...

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\Mypp.dll" 
stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
  </system.webServer> 

我希望看到有关我应用的 XDT 文件中的连接超时的信息。那么,也许这不是正确的 web.config 文件?

我不是 Azure 专家,在这一点上,我觉得我在浪费时间,所以我想检查一下是否有人有任何建议。


请求超时:

指定 ASP.NET Core 模块等待侦听 %ASPNETCORE_PORT% 的进程响应的持续时间。

在 ASP.NET Core 2.0 或更早版本附带的 ASP.NET Core 模块版本中, requestTimeout 必须仅以整分钟指定,否则默认为 2 分钟。

您可以尝试添加requestTimeout="00:20:00在插槽站点/wwwroot 文件夹中的 web.config 中。

<aspNetCore
  requestTimeout="00:20:00"
  processPath="%LAUNCHER_PATH%"
  arguments="%LAUNCHER_ARGS%"
  stdoutLogEnabled="false"
  stdoutLogFile=".\logs\stdout">
  <environmentVariables>
    <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="staging" /> <!-- value could be "development", "staging" or "production"-->
  </environmentVariables>
</aspNetCore>

更详细的内容,您可以参考这篇文章来了解ASP.NET Core 模块配置参考 https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-2.0#attributes-of-the-aspnetcore-element

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何增加 ASP.NET Core 2.0 API 的 Azure 应用服务超时 的相关文章

随机推荐