pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

PM2 does not restart crashed processes

Open neilgupta opened this issue 3 years ago • 1 comments
trafficstars

With autorestart set to true, PM2 will restart child processes if they disconnect. However, if the process crashes internally, PM2 will not attempt to restart or replace it, leaving the overall service running with one less process.

In our case, we just upgraded to node 16 and PM2 5.2.0, and are seeing node periodically throw ERR_IPC_CLOSED now. We're not sure about the root cause of that error yet, but regardless, we would expect PM2 to either handle that or at least restart the crashed process. Unfortunately, it's doing neither and just letting the process permanently die.

This appears to be because PM2 marks the process as ERRORED_STATUS in its error event handler, and ERRORED_STATUS processes do not even attempt to restart.

My proposed fix here skips marking the process as ERRORED_STATUS on a single error event, instead reserving that status for repeated crashes. This is the simplest solution, but I'm open to other ideas/approaches here.

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
License MIT

neilgupta avatar Jul 01 '22 17:07 neilgupta

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jul 01 '22 17:07 CLAassistant

good catch

Unitech avatar Sep 08 '22 07:09 Unitech