Azure Asp .Net Webapp the Request Timed Out

Azure ASP .net WebApp The request timed out

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.

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

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

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

The request timed out. The web server failed to respond within the specified time

This problem occurs because of the browser. There is no problem with your code, no need to modify httpRuntime.

The browser has a default connection timeout, Chrome seems to be about 5 minutes, and the actual test shows 500-The request timed out. in about 4 minutes.

Test Code

public int test()
{
try
{
DateTime dt1 = DateTime.Now;
DateTime dt2 = dt1.AddMinutes(10);
while (DateTime.Now < dt2)
{
Thread.Sleep(1000);
Tick("I am running");
}
return 1;
}
catch (Exception)
{
return -1;
throw;
}
}

public void Tick(object data)
{
_logger.LogInformation(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + data);
}

Phenomenon

Sample Image

About 4 minutes or so, a 500 timeout error occurred in the browser, but I found that the backend was still running and the log was still recording.

Sample Image

Suggestion

If the backend needs to process for an hour to return the result, it must return the result asynchronously. Synchronization is impossible, there is no reason to synchronize, even if the browser does not time out, you do not need to return synchronously, wasting resources.

To return the processing results in time, you can use WebSocket and Ajax polling, or signalr.

During the processing, the front end only needs to provide the Loading prompt, and then poll regularly to query the back-end processing results. If the processing is successful, the front-end prompt is updated successfully.

Increase azure web app request timeout

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

Azure ASP .net WebApp - 500 Error - The request timed out

Make any long processing in a web job not inside the HTTP request.

When the user submit the request, get the excel file, upload it to an Azure Storage Account, store the path in the database and post a message in a queue.
Make the web job listen for the queue and do the needed processing.

You can communicate the results back using SignalR, the web job can send a message to a SignalR hub and the web application can get this message and display it for the user.

Azure 500 - The request timed out custom error page

We are making changes to ensure less processing is done on the Web request, however there may still be a chance that these limits are hit. Does anyone know if there is a way to configure a custom error page to be shown instead of the generic error page shown below?

Since you could not overcome the limitation about request timeout (230 second) in Azure App Service, you need to either optimize your server-side processing or you need to catch the exception and customize the response. I tried to capture the exception by using Application_Error event and custom HTTP Modules, but failed in the end.

For a workaround, you could specify the timeout for your action and capture the exception in your application before the timeout exception thrown by Azure App Service, then you could add your custom error page. You could leverage AsyncTimeoutAttribute and define your action as follows:

[AsyncTimeout(duration:10000)] //The timeout value in milliseconds.
[HandleError(ExceptionType = typeof(TimeoutException),
View = "TimeoutError")]
public async Task<ActionResult> LongTask(CancellationToken cancellationToken)
{
await Task.Delay(TimeSpan.FromSeconds(20), cancellationToken);
return Content("Done");
}

Note: HandleErrorAttribute requires customErrors to be enabled in your Web.Config. If the TimeoutException happens, then you would be redirected to the particular MVC view you defined.

Azure Web Apps Timeout long process request

So that is how I settle down in this process.

if that is a long run process, it shall be handle on web job, I have rewrite entire process into webjob by using Azure WebJob SDK on visual studio 2015.

Also, in order to speed up entire process (just to save cost on azure credit), I direct use DatabaseContext and make every required table runnig on ToList() with anonymous type. Finanlly, I get a list of item that needed to insert, and use BulkInsert.

Everything is done in 3 minutes Azure run time with 70k entries.

// Update for latest implementation

I am still using WebJob for some background process, but I speed up my process by using EntityFramework BulkInsert, along with Parallel.ForEach() for my logical process.
Further more, I also use Parallel.ForEach() with using(var context=new DatabaseContext()){...} when deal with bulk update. (There is bulk.update library out there provide good solution too)

Besides, I do try Azure.Functions that seem to be replacement for Auzre.WebJob. It is faster trigger than WebJob by using same queue trigger.

For all background process, Azure come with few solutions for you, just share incase anyone need this.

  • WebJob
  • Functions
  • Logic Apps


Related Topics



Leave a reply



Submit