2

I have hosted an ASP .NET web app in Azure App service. the function of web app is read the data from excel and match the data in Azure SQL database and post the data via API. The app runs good but the problem is that it wont run for longer time it throws an Error like

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

I have also increased the execution time limit in Web.Config file.

<system.web>
    <customErrors mode="Off" />
    <compilation targetFramework="4.6.1" />
    <httpRuntime maxRequestLength="2097152" executionTimeout="300000" targetFramework="4.6.1" />
</system.web>

Can any one please help here what I can do for this. Can I get minimum of 1 hour execution time?

Abdul
  • 176
  • 3
  • 19

1 Answers1

6

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

enter image description here

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.

enter image description here

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.

Jason Pan
  • 15,263
  • 1
  • 14
  • 29