So just for completeness and clarity, the error you are seeing on your 
backend service "upstream prematurely closed connection while reading 
response header from upstream" strictly means that the nginx proxy on that 
specific instance of your backend service fails to contact the webserver 
(aka your app) in that instance (it is all localized to a specific 
instance). 

Normally these often occur due to nginx's health checks failing, but this 
can also just happen when nginx does its normal job of proxying incoming 
requests to your application. Essentially, the connection between nginx and 
your application closes due to your application not responding to it, or 
your application completely stops listening to nginx (it listens on port 
8080 
<https://cloud.google.com/appengine/docs/flexible/nodejs/runtime#application_startup>
 
as seen in the error). 

Therefore, the issue all comes down to your application code and the 
Node.js runtime. Node.js is a single threaded runtime, this means that your 
code must be properly coded to take full advantage of Node.js's event loop 
<https://blog.risingstack.com/node-hero-async-programming-in-node-js/> in 
order to be asynchronous. By having async code, you are allowing concurrent 
requests to be executed, which in turn allows your application to always 
listen and respond to nginx. Once your application becomes asynchronous, it 
is able to properly live and scale in the cloud.  

Note that you should always perform exponential backoff-retry 
<https://cloud.google.com/storage/docs/exponential-backoff> on the 
client-side (aka you proxy service) in the case that your backend service 
becomes too busy and times out. This way, even if you see 5xx responses, 
your client should always eventually succeed (once your backend has 
recovered). 


-- 
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/e504581a-843b-4e6e-aee2-74bef46adfcc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
  • [google-appengine]... Marco Galassi
    • [google-appen... 'Jordan (Cloud Platform Support)' via Google App Engine
      • [google-a... 'Jordan (Cloud Platform Support)' via Google App Engine
        • [goog... Marco Galassi
          • [... 'Jordan (Cloud Platform Support)' via Google App Engine
            • ... Marco Galassi
              • ... 'Jordan (Cloud Platform Support)' via Google App Engine
                • ... Marco Galassi
                • ... 'Jordan (Cloud Platform Support)' via Google App Engine
                • ... Marco Galassi
                • ... Jonas Klemming
    • [google-appen... Marco Galassi

Reply via email to