53

Is there any way to increase the request timeout for azure web apps?

If I delay the request by anything over 2 minutes or so the request fails with no error (blank page returned) or a vague 503 response.

    public ActionResult Index()
    {
        System.Threading.Thread.Sleep(230000);
        return View();
    }

I have some long running requests that I need to run (uploading large files/large pdf conversion jobs) - is there any way around this? I'd prefer to avoid using VM hosting is possible. I've tried scaling the web app to basic or standard plans, but it doesn't seem to make any difference.

2
  • 5
    Did you ever figure this out? I am having same issue. Commented Dec 26, 2015 at 4:44
  • 1
    Nope, ended up having to host on a VM Commented Jan 2, 2016 at 9:13

7 Answers 7

40

No, you cannot increase the timeout for Azure App Services (it is 230 seconds). You can move to a cloud services or IIS hosted on a VM where you have control over those settings. You can also move to an async model where the client makes a request, gets some sort of ticket or identifier that is can poll back to see if the processing is done. There are many examples of async type models for web apps out there you can choose from. Ref:https://social.msdn.microsoft.com/Forums/en-US/05f254a6-9b34-4eb2-a5f7-2a82fb40135f/time-out-after-230-seconds?forum=windowsazurewebsitespreview

Sign up to request clarification or add additional context in comments.

5 Comments

Sanders Can you provide a link to the Microsoft documentation for this ? I'm trying a similar scenario of uploading files through Azure App Service, and from what I'm seeing the limit appears to be about 5 minutes, rather than 2.
Updated in line. 230 seconds is the default.
I've done some testing and the timeout is actually 240 seconds (4 minutes).
In my experience the timeout is 120 seconds (2 minutes), on a linux App Service with a docker container.
what is the configuration property to set the timeout value default to 5 mins ? @JeffSanders-MSFT
36

You can use my trick code here to by-pass 230s limit. In summary, we just keep writing empty html value "\r\n" to response to let ALB know that we are returning data, but actually we are processing the request.

Sample code

10 Comments

What a nasty trick. And by nasty I mean I'm saving it for later.
I suppose you could do TCP Keep-Alive to achieve the same.
@quinvit please can you share the entire trick code
@DavidKlempfner Azure Load Balancer
So this didn't work for me - triggers the anti-forgery token, but maybe it'll help someone else. This is what I came up with: gist.github.com/Nixon-Joseph/040834e532d2cd24be681f9147403992
|
4

Hope this would be some help https://azure.microsoft.com/en-us/blog/new-configurable-idle-timeout-for-azure-load-balancer/. But I think it's bad idea keep request while some heavy job being executed. Imho, you'd better implement background job and check it status from client from time to time.

1 Comment

I've had a read through the link - does any of that apply to azure web apps? Should I try and configure TCP Keep-Alive for the specific action where the timeout could occur?
2

You can deploy the web app using the automation script and add this line under "resources":

        {
          "name": "WEBSITES_CONTAINER_START_TIME_LIMIT",
          "value": 1800
        },

where value is by default 230, but can be increased up to 1800. You can also add a New Setting under Application Settings, named WEBSITES_CONTAINER_START_TIME_LIMIT and with the value of seconds you want.

2 Comments

Didn't work for me. This might work only for Linux and as propery, not resources?
I think it's a limit for start time of the app service to avoid a restart of the container. More info can be found here learn.microsoft.com/en-us/azure/app-service/containers/…
1
az webapp config appsettings set --resource-group <you-resource-group-name> --name <your-app-name> --slot <your-slot-name> --settings WEBSITES_CONTAINER_START_TIME_LIMIT=1800

https://learn.microsoft.com/en-us/archive/blogs/waws/things-you-should-know-web-apps-and-linux

"If your container takes a long time to start, increase the start time limit. Applies to Web App for Containers When we start your container, we'll wait a while for it to start and initialize. We consider the startup to be successful once the container is running and once we get a response to a ping so that we know it's ready to respond to HTTP traffic. We'll wait 230 seconds for that to happen. If we don't have a successful start within 230 seconds, we'll assume there's a problem and we'll stop the container.

We realize that some containers might need more time than that to start, so we allow you to increase that 230 second wait time up to a limit of 1800 seconds. To configure that, add an app setting called WEBSITES_CONTAINER_START_TIME_LIMIT and set it to the number of seconds you would like for us to wait for your container to start (up to a maximum of 1800) as shown in the image below."

Comments

-1

Try making your action Async if it is supposed to be long running to avoid deadlocks on your web server:

public async Task<ActionResult> Index()
{
    await Task.Delay(230000);
    return View();
}

And you can set script timeout in the code in the controller:

HttpContext.Current.Server.ScriptTimeout = 300;

Note that HttpContext is instantiated on a per request basis, so it would be back to the default value on the next request

4 Comments

Unfortunately this didn't work either public async Task<ActionResult> Index() { HttpContext.Server.ScriptTimeout = 100000; System.Threading.Thread.Sleep(400000); return View(); }
@woggles do you have this code hosted anywhere that I can give it a try?
just deployed to webapplication45946.azurewebsites.net which won't be around forever, but it fails regardless of where I deploy the web app - I can only get it to run successfully if I host it on a VM
@woggles after you created a VM, was there any setting you needed to adjust to allow for longer execution?
-7
+25

You have to some changes in web.config

<system.webServer> 

<monitoring> 

<triggers>

<statusCode>

<addstatusCode="500"subStatusCode="0"win32StatusCode="0"

count="10"timeInterval="00:00:30" /> 

</statusCode>

</triggers>

<actionsvalue="Recycle" /> 

</monitoring> 

For more:

Connection Timeout (Timeout Expired) on Azure Web App Site

7 Comments

Those don't seem to be vaild tags for my web.config file...The element 'system.webServer' has invalid child element 'monitoring'.
plz use <configuration> before <system.webServer> and </configuration>
after </system.webserver>
This does not do what the OP asked. Your answer recycles the app pool, which would cancel any operations in progress. That defeats the purpose.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.