Does pm2 provide native mechanisms to prevent duplicate writes during restart loops?
0 reputation · 31 Dec 2024, 01:47 UTC
PM2 manages process lifecycles by automatically restarting applications that exit with non-zero codes. While features like exp-backoff-restart-delay and max_restarts control the frequency and limit of these attempts, the process manager operates independently of the application's internal state.
When a process crashes during a write operation, PM2 triggers a full restart of the Node.js instance. Because PM2 does not track the internal progress of the application's logic, there is a risk that a restarted process may re-execute the same write operation, potentially leading to duplicate data entries if the application lacks its own idempotency logic.
Which PM2 configurations, if any, can be used to signal to the application that it is recovering from a crash rather than starting fresh? Does PM2 offer a way to maintain a persistent state across restarts to prevent redundant operations?