Score:0

PM2 Cluster Mode - All Clusters restarting on error

mx flag

I am running a NodeJS application in Cluster mode: pm2 start server.js -i max

Assume I have 2 clusters (0 and 1)... Our application is a simple NodeJS backend app running Express. However, there is the occasion where there is an unhandled error that causes the app to go down (thus PM2 needs to restart). I am noticing that whenever PM2 restarts on cluster mode, however, it brings ALL clusters down temporarily to restart them ALL...but I simply need the worker thread to restart, not all of the threads that did not error.

Our app needs a few seconds to "reboot" before it can accept connections (needs to connect to DB). Therefore, we don't want the restarting cluster to be 'online' until about 30 seconds after the restart. We tried using --listen-timeout 30000 but the issue still appears to be that all clusters are restarting

Notes:

  • Running on Node 18.7.0
  • Nginx reverse proxy

I created a fake endpoint that has a hardcoded unhandled error to test. Whenever I hit this endpoint, and re-check the status pm2 status it shows all clusters increasing in their "restart quantity" value.

We encountered this issue on PM2 5.2.0 and also tried updating to 5.3.0 and made no difference.

We tried using --listen-timeout 30000 but the issue still appears to be that all clusters are restarting

The app has try/catch error handlers implemented, but the point is that PM2 isn't working as we'd expect. On the off chance we miss an error, we need PM2 to not bring everything down.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.