简体   繁体   English

Azure ASP .net WebApp请求超时

[英]Azure ASP .net WebApp The request timed out

I have deployed an ASP .net MVC web app to Azure App service. 我已经将ASP .net MVC Web应用程序部署到Azure App服务。

I do a GET request from my site to some controller method which gets data from DB(DbContext). 我从我的网站做一个GET请求到一些从DB(DbContext)获取数据的控制器方法。 Sometimes the process of getting data from DB may take more than 4 minutes. 有时,从数据库获取数据的过程可能需要4分钟以上。 That means that my request has no action more than 4 minutes. 这意味着我的请求没有超过4分钟的动作。 After that Azure kills the connection - I get message: 之后Azure杀死连接 - 我收到消息:

500 - The request timed out. 500 - 请求超时。

The web server failed to respond within the specified time. Web服务器无法在指定时间内响应。

This is a method example: 这是一个方法示例:

 [HttpGet]
    public async Task<JsonResult> LongGet(string testString)
    {            
       var task = Task.Delay(360000);
        await task;            
        return Json("Woke", JsonRequestBehavior.AllowGet);
    }

I have seen a lot of questions like this, but I got no answer: 我见过很多像这样的问题,但我没有回答:

Not working 1 Cant give other link - reputation is too low. 不工作1不能给其他链接 - 声誉太低。

I have read this article - its about Azure Load Balancer which is not available for webapps, but its written that common way of handling my problem in Azure webapp is using TCP Keep-alive. 我已经阅读了这篇文章 - 它关于Azure负载均衡器,它不适用于webapps,但是它写的是在Azure webapp中处理我的问题的常用方法是使用TCP Keep-alive。 So I changed my method: 所以我改变了我的方法:

[HttpGet]
    public async Task<JsonResult> LongPost(string testString)
    {
        ServicePointManager.SetTcpKeepAlive(true, 1000, 5000);
        ServicePointManager.MaxServicePointIdleTime = 400000;
        ServicePointManager.FindServicePoint(Request.Url).MaxIdleTime = 4000000;
       var task = Task.Delay(360000);
        await task;            
        return Json("Woke", JsonRequestBehavior.AllowGet);
    }

But still get same error. 但仍然得到相同的错误。 I am using simple GET request like 我正在使用简单的GET请求

GET /Home/LongPost?testString="abc" HTTP/1.1
Host: longgetrequest.azurewebsites.net
Cache-Control: no-cache
Postman-Token: bde0d996-8cf3-2b3f-20cd-d704016b29c6

So I am looking for the answer what am I doing wrong and how to increase request timeout time in Azure Web app. 所以我正在寻找答案我做错了什么以及如何在Azure Web应用程序中增加请求超时时间。 Any help is appreciated. 任何帮助表示赞赏。

Azure setting on portal: 门户网站上的Azure设置:

Web sockets - On Web套接字 - 打开

Always On - On 永远在线 - 开

App settings: 应用设置:

SCM_COMMAND_IDLE_TIMEOUT = 3600 SCM_COMMAND_IDLE_TIMEOUT = 3600

WEBSITE_NODE_DEFAULT_VERSION = 4.2.3 WEBSITE_NODE_DEFAULT_VERSION = 4.2.3

230 seconds . 230秒 That's it. 而已。 That's the in-flight request timeout in Azure App Service. 这是Azure App Service中的飞行中请求超时。 It's hardcoded in the platform so TCP keep-alives or not you're still bound by it. 它在平台上是硬编码的,因此TCP保持不变,你仍然受其约束。

Source -- see David Ebbo's answer here: 来源 - 请参阅David Ebbo的回答:
https://social.msdn.microsoft.com/Forums/en-US/17305ddc-07b2-436c-881b-286d1744c98f/503-errors-with-large-pdf-file?forum=windowsazurewebsitespreview https://social.msdn.microsoft.com/Forums/en-US/17305ddc-07b2-436c-881b-286d1744c98f/503-errors-with-large-pdf-file?forum=windowsazurewebsitespreview

There is a 230 second (ie a little less than 4 mins) timeout for requests that are not sending any data back. 对于未发送任何数据的请求,有230秒(即少于4分钟)超时。 After that, the client gets the 500 you saw, even though in reality the request is allowed to continue server side. 之后,客户端获得您看到的500,即使实际上允许请求继续服务器端。

Without knowing more about your application it's difficult to suggest a different approach. 如果不了解您的应用程序,很难提出不同的方法。 However what's clear is that you do need a different approach -- 然而,很明显,你确实需要一种不同的方法 -

Maybe return a 202 Accepted instead with a Location header to poll for the result later? 也许返回202 Accepted而不是Location标题以便稍后轮询结果?

我刚刚将我的Azure网站从共享环境更改为标准版,它可以正常工作。

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

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