💡 Learn more : App Service Documentation.
There are reasons that you might have a request that takes 2-3 minutes to complete and this post is for you. For most, you should probably look at decoupling these long running request.
If you're using ASP.NET Core 2.0 API and deploying to an Azure App Service, then you might run into an issue where it takes a process request longer than 2 minutes to complete. You'll typically get a
502 Bad Gateway with the following info:
"The specified CGI application encountered an error and the server terminated the process".
If you check your diagnostic logfile you might see:
018-06-15 03:47:03.232 +00:00 [Error] Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware: An unhandled exception has occurred while executing the request System.Threading.Tasks.TaskCanceledException: A task was canceled.
You can fix this by going into your web.config in your sites/wwwroot folder and adding a
requestTimeout="00:20:00 to the file as shown below.
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.webServer> <handlers> <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" /> </handlers> <aspNetCore processPath="dotnet" arguments=".\WebApplication1.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" requestTimeout="00:20:00" /> </system.webServer> </configuration> <!--ProjectGuid: 3b93921c-f843-46c8-914e-xxx-->