2

Background:

  • .net core 2.2 web application
  • Deployed in Azure web app using Azure ARM
  • There is no DB involved. The app is trying to read some information from keyvault.

Issue reproduction steps

  • Application works locally
  • Deploy the app using Azure ARM
  • After successful deployment, navigation to web app causes 502 & 500 error. I have attached the screenshot.enter image description here

What I have tried so far

  • Turned on diagnostic logs - I didn't find anything interesting.
  • I have already tried this and several others SO answers - no luck
  • Restarting the web app doesn't help either. However, the app starts working as soon as I alter any azure app application settings - even changing a value of WEBSITE_HTTPLOGGING_RETENTION_DAYS from 2 to 5 gets the app running.

Please advise how to troubleshoot this error?

3
  • Does app has permission to key-vault? and as good tone it would be nice to post some code Commented Mar 20, 2019 at 4:16
  • Yes, the app has permission to key-vault. As I mentioned everything works just fine in local. Commented Mar 20, 2019 at 5:55
  • What did you end up doing. I've been getting this for several days now. it just starts happening in azure. Commented Dec 13, 2019 at 5:01

1 Answer 1

3

502 bad gateway error response is not like traditional 500 error which is mostly a code problem, this make it even difficult to troubleshoot the root cause

Basically, the HTTP 502 Bad Gateway server error response code indicates that the web server (IIS in our scenario), while acting as a gateway or proxy, received an invalid response from the upstream server. This can happen for multiple reasons - for example, failure to connect to the upstream server, no response from the up stream server, or the up steam server took too long to respond (time out). As a result, the server which is acting as a gateway or proxy will report that as a status of 502. The reason why 502 is difficult to troubleshoot is because the root cause could vary a lot and will be dependent on real application framework, such as Asp.Net, PHP, Java etc.

For ASP.NET Core application, as we know, in order to host the application in IIS, we need install AspNetCoreModule. It is actually a native module in IIS acting as a reverse proxy for dotnet core application, that's why we may experience 502 error for ASP.NET Core application.

Though 502 error could also be caused by underlying platform issue such as disk/storage problem, in most condition, we need to focus on the components running in the upstream server (root cause), and IIS log will give us information about how to narrow down the issue.

Now, suppose we experience 502 error when accessing an ASP.Net Core application, the sub status code might not be helpful enough. Firstly, we can have a check for the IIS log and verify the root cause by sc-win32-status code. Alternatively, we can enable Failed Request Tracing to know more details.

enter image description here

The above log give us two import information, the error comes from AspNetCoreModule and the error code is 2147954402. That means, the 502 error is fired by AspNetCoreModule and it probably has experienced some invalid response. Furthermore, we can use either err utility or visit http://errors/ to figure out 2147954402 is just WININET_E_TIMEOUT. By default, ASP.NET Core request time out is 2 minutes, and we can change it via requestTimeout in setting file. For more ASP.NET Core configuration, please refer to ASP.NET Core Module configuration reference.

Also i would request you to go through the troubleshoot guide of asp.net core 2.2 application .

https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/azure-apps/troubleshoot?view=aspnetcore-2.2

Hope it helps.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.