Azure ASP .net WebApp请求超时 [英] Azure ASP .net WebApp The request timed out

查看:117
本文介绍了Azure ASP .net WebApp请求超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将ASP .net MVC Web应用程序部署到Azure App服务.

I have deployed an ASP .net MVC web app to Azure App service.

我从站点向某个控制器方法发出GET请求,该方法从DB(DbContext)获取数据.有时,从数据库获取数据的过程可能需要4分钟以上的时间.这意味着我的请求没有超过4分钟的动作.之后,Azure终止了连接-我收到消息:

I do a GET request from my site to some controller method which gets data from DB(DbContext). Sometimes the process of getting data from DB may take more than 4 minutes. That means that my request has no action more than 4 minutes. After that Azure kills the connection - I get message:

500-请求超时.

Web服务器失败 在指定时间内做出反应.

500 - The request timed out.

The web server failed to respond within the specified time.

这是一个方法示例:

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

我已阅读此 article -有关Azure负载均衡器的信息,该负载不适用于Web应用程序,但它写到在Azure Webapp中处理我的问题的常用方法是使用TCP Keep-alive.所以我改变了方法:

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. 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 /Home/LongPost?testString="abc" HTTP/1.1
Host: longgetrequest.azurewebsites.net
Cache-Control: no-cache
Postman-Token: bde0d996-8cf3-2b3f-20cd-d704016b29c6

所以我正在寻找答案,我做错了什么以及如何增加Azure Web应用程序中的请求超时时间.任何帮助表示赞赏.

So I am looking for the answer what am I doing wrong and how to increase request timeout time in Azure Web app. Any help is appreciated.

门户网站上的天蓝色设置:

Azure setting on portal:

Web套接字-开

始终打开-打开

应用设置:

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秒.而已.这就是Azure App Service中的正在进行的请求超时.它在平台中进行了硬编码,因此无论您是否保持TCP保持活动状态,都仍然受它约束.

230 seconds. That's it. That's the in-flight request timeout in Azure App Service. It's hardcoded in the platform so TCP keep-alives or not you're still bound by it.

来源-在此处查看David Ebbo的答案:
https://social.msdn.microsoft.com/Forums/zh-CN/17305ddc-07b2-436c-881b-286d1744c98f/503-errors-with-large-pdf-file?forum=windowsazurewebsitespreview

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

对于未发送回任何数据的请求,会有230秒(即不到4分钟)的超时时间.之后,即使实际上请求被允许继续服务器端,客户端也会获得您看到的500.

There is a 230 second (i.e. a little less than 4 mins) timeout for requests that are not sending any data back. After that, the client gets the 500 you saw, even though in reality the request is allowed to continue server side.

在不了解您的应用程序的情况下,很难提出另一种方法.但是很明显,您确实需要一种不同的方法-

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

也许返回202 Accepted而不是Location标头以便以后查询结果?

Maybe return a 202 Accepted instead with a Location header to poll for the result later?

这篇关于Azure ASP .net WebApp请求超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆