ASP.Net Core - 502 Bad Gateway / Invalid Response

Today I received the following error from a long running API endpoint.  This is a .Net Core site running on IIS.


    502 - Web server received an invalid response while acting as a gateway or proxy server.
    There is a problem with the page you are looking for, and it cannot be displayed. When the Web server (while acting as a gateway or proxy) contacted the upstream content server, it received an invalid response from the content server.

There are many timeouts in play in a lot of applications. You could have request timeouts, database timeouts, etc. In this case it was the ASP.Net core executable timing out. To fix this I updated the "aspNetCore" tag in the web.config file for the site. The below example will extend the timeout to 15 minutes.


<aspNetCore processPath=".\MySite.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" requestTimeout="00:15:00" />

As a final note, be mindful about how high you extend your timeout as this will affect every request to your site.

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.