简体   繁体   中英

How does Node.JS in App Engine Standard handle crashes?

When a function in node crashes, it tends to bring down the entire app. This is mitigated by solutions like pm2 and/or having global listeners for uncaught exceptions.

How is this handled in AppEngine Standard NodeJS? If an uncaught exception happens - are they automatically recovered (and logged) - allowing other functions still able to run, or must some manual work be done to handle this situation?

If your Node.js app crashes, AppEngine will log it's errors in its Logging mechanism and will restart. If it keeps crashing, it will mark the application as unhealthy:

Google App Engine Node.js Application Unhealthy

If you don't want to depend on AppEngine, you can always add this code snippet to all your Node.js apps:

const someFn = // do something to handle exceptions
process.on("unhandledRejection", someFn );

Although I would advise against it.

For me, personally, I prefer having my machine in Google Cloud ( no AppEngine ) and have a server for me where I can have PM2 and where I can spice it how I want, but if you are invested in AppEngine, this is the best you can do.

Another thing you need to keep in mind is that even though GAE logs errors, you do have a log limit , so if your application is crashing all the time, you will eventually hit it.

Also, using Monads in your code ( cough cough Sanctuary / Folktale ) that force you to deal with exceptions also helps :P

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM