Today I received the following error from a long running API endpoint. This is a .Net Core site running on IIS.
Error
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.
web.config
<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.