本文介绍了如何为我的ASP.NET Core 2.0 API增加Azure App Service的超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有要部署到Azure应用服务的ASP.NET Core 2.0 API。直到最近,当我不得不处理一个耗时超过2分钟的请求,并且收到502错误的网关声明

I have an ASP.NET Core 2.0 API I am deploying to an Azure App Service. This has been working fine until recently when I had to process a request that took longer than 2 minutes to complete and I got a 502 Bad Gateway stating

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

当我在此过程中碰到2分钟标记时,就会持续发生这种情况。

This consistently happens when I hit the 2 minute mark on this process.

我的诊断日志文件说

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;

I am working on the assumption that this is a timeout issue because it is always at the 2 minute mark and I know the request takes more than 2 minutes to complete. So I was looking into how to increase the timeout and found some posts on SO that talked about using an applicationHost.xdt file, placing it in the root of the Site folder for the site. I am using this 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调试控制台将其上载到部署槽的Site文件夹的根目录时我正在测试我的API,然后查看转换文件,看到以下内容;

When I upload it, using Kudu debug console, to the root of the Site folder for my deployment slot I am using to test my API and then look at the transform file, I see the following;

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转换。

which to me looks like it successfully applied the XDT transform.

但是,即使重新启动基本App Service和相关的部署程序t插槽。我仍然遇到错误。

However even after restarting the base App Service and the related deployment slot. I am still getting the error.

所以,我使用了错误的超时设置吗?

So, am I using the wrong timeout setting?

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

When I look at the web.config file in my slots sites/wwwroot folder, it contains only this...

<?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文件?

I expected to see the information about the connectiontimeout that was in the XDT file I applied. So, perhaps this is not the right web.config file?

我不是Azure专家,在这一点上,我觉得我在浪费时间,所以我想

I am not an Azure expert and at this point, I feel like I am wasting time so I wanted to check an see if anyone has any suggestions.

推荐答案

requestTimeout

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

In versions of the ASP.NET Core Module that shipped with the release of ASP.NET Core 2.0 or earlier, the requestTimeout must be specified in whole minutes only, otherwise it defaults to 2 minutes.

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

You could try to add the requestTimeout="00:20:00 in web.config in your slots sites/wwwroot folder.

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

有关更多详细信息,您可以参考本文以了解

For more details, you could refer to this article to learn about ASP.NET Core Module configuration reference

这篇关于如何为我的ASP.NET Core 2.0 API增加Azure App Service的超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 02:25