502 errors are often caused due to your application code being too busy to respond to nginx (the webserver that sits in front of your app that accepts and routes requests to and from your app).
Nginx will return a 502 back to the load balancer which is returned back to the client if it is not able to communicate with your app. It is therefore recommended to ensure that you are properly coding for Node-js and that you are not blocking the
Node-js Event Loop in order to always respond to nginx.
If your application becomes too busy, and doesn't make time to accept and respond to health checks from nginx, nginx will stop communicating with your application and render it as unhealthy (and attempt to restart it, in turn stopping all requests it was handling). A busy application will also force new incoming requests to wait until previous requests have completed. This will cause increased latency for each new incoming request as they each wait in the pending queue for room on your instance.
You can use the
App Engine Dashboard to view the resource usage, latency, and traffic patterns of your app, and pinpoint a timestamp with high latency. Then use the
Stackdriver Log viewer to see what happened in your code at that timestamp. Just ensure you choose the 'nginx.error', 'nginx.request', 'stderr', and 'stdout' log options to see all incoming requests, errors, and debug output from your application. If a request receives a 502, this means it never made it to your application (since nginx couldn't reach it), and the logs will therefore be seen at the loadbalancer level (by selecting the 'Cloud HTTP Load Balancer' logs and not 'GAE Application' logs).
- Note: Google Groups is reserved for general product discussions and not for technical support. For further technical support it is recommended to post your
detailed questions to
Stack Exchange using the supported Cloud tags.