.NET Core 2.0 on Azure results in a 502.3 CGI Error

2

The past few days I tried to find the answer to the following error message that plagued my .NET Core 2.0 application on Azure Web App hosting:

This error occurs when a CGI application does not return a valid set of HTTP headers, or when a proxy or gateway was unable to send the request to a parent gateway. You may need to get a network trace or contact the proxy server administrator, if it is not a CGI problem.

Because it took several days to find the answer, I'm posting my solution here.

Next to the CGI error, I also found the following error code in the error log: 0x80072ee2. This is an indication that the request experienced a timeout. However, Azure has a timeout limit of 4 minutes and the error appeared after approximately 1,5 min. The application was designed to handle the request under 4 minutes, so a timeout error should not occur.

azure
.net-core
cgi
asked on Stack Overflow Sep 3, 2017 by MartinH

1 Answer

2

I found the solution after I read the following page: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/?tabs=aspnetcore2x. In this page the relation between IIS and the Kestrel engine is explained. Although the web app hosting should be different than IIS hosting, I suspect that Azure uses a lot of the IIS module, because there are many similarities.

The following issue on github was also a piece to the solution of my problem: https://github.com/aspnet/IISIntegration/issues/311. In this issue it is explained that next to IIS, Kestrel also has a timeout limit of 2 minutes. I completely missed that bit of information when searching for a solution at first. Changing the timeout of the Kestrel server (which can be found on the following page: https://docs.microsoft.com/en-us/aspnet/core/hosting/aspnet-core-module) solved my problem and let the request run in 2,5 minutes.

I later checked the exact duration before the timeout shows with Chrome developer tools and it appeared to be exactly 2 minutes, which should have been a more early clue that my problem was the timeout of the Kestrel server.

answered on Stack Overflow Sep 3, 2017 by MartinH

User contributions licensed under CC BY-SA 3.0