pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

PM2 restarts app when a subprocess was killed by the OOM killer

Open Choppel opened this issue 11 months ago • 0 comments

I have a node app running via pm2. The app itself spawns some processes like imagemagick's convert to convert some images in a folder. It can happen, that the convert call may use too much memory and get killed by the systems OOM killer with the message:

Out of memory: Killed process 111337 (convert) total-vm:562060kB, anon-rss:416096kB, file-rss:4kB, shmem-rss:67340kB, UID:0 pgtables:1060kB oom_score_adj:1000

This is fine. In this case my app would log an error that this process was not successful.

However, right after the OOM killer killed the sub process, pm2 kills my node app with the following message:

systemd[1]: pm2-root.service: A process of this unit has been killed by the OOM killer. pm2[111342]: [PM2] Applying action deleteProcessId on app [all](ids: [ 0, 1, 2 ])

It seems, that pm2 detects that the OOM killer killed a sub process and then calls an internal method deleteProcessId on all apps. Because of this, my app cannot log any error. It does get restarted, but then tries the same file until it gets killed again. Is this the default behavior of pm2? Can this behavior be bypassed?

Choppel avatar Jan 31 '25 21:01 Choppel