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 
<https://nodejs.org/en/docs/guides/dont-block-the-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  
<http://console.cloud.google.com/appengine/instances>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 
<http://console.cloud.google.com/logs/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 <https://stackoverflow.com/help/how-to-ask> to 
Stack 
Exchange <https://cloud.google.com/support/docs/stackexchange>using the 
supported Cloud tags. 


-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/25ba5413-6cac-47fc-be4c-87c9dbe86c6e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to