Node.js PM2 log : App [server:0] exited with code [0] via signal [SIGKILL]
Asked Answered
P

3

9

In my Node.js application I am calling an external API which takes more than 7 minutes to get the response, in the meantime I am getting this:

PM2 log : App [server:0] exited with code [0] via signal [SIGKILL]

and the process is getting killed.

Policeman answered 20/11, 2019 at 5:55 Comment(0)
S
10

This fixed my problem.

First Stop & Delete your current running PM2 App.

pm2 stop <app name>

pm2 delete <app name>

Then execute the below commands:

pm2 kill

rm -rf ~/.pm2

Now start your app again and see the logs.

pm2 start <app name>

pm2 logs

Sauer answered 26/10, 2020 at 17:53 Comment(3)
I was like "Why the hell would I need to "rm -rf ~/.pm2"?" Then it really solved my issue after trying everything, thanks!Chingchinghai
I'm glad it helps!Sauer
This can only temporarily solve my problem, but it cannot completely solve it.Ptosis
J
3

Just had this happen to me too. The key was SIGKILL, which meant something was killing the process intentionally.

Looking in dmesg I could see that the Linux OOM (out-of-memory) handler was terminating the process, which it was doing because the process had briefly exceeded the amount of memory I had allocated to the Docker container it was running inside.

In this case, increasing the available memory the process was permitted to use fixed the problem.

Jijib answered 30/3, 2022 at 14:12 Comment(0)
D
2

Usually in web waiting even one minute is already kind of signal. Chrome standard timeout is 3 minutes, so I think you should definitely check if your server not throwing timeout error on your request to external API.

Also good practice of server writing is to make it never crash on error, always wrap everything with try catch, use validations to catch errors and send back some prepared response, or in worst case just output error in server console, but still make server available to provess other requests after this.

PM2 is daemont but it is helpful only if your server crash sometimes and need to be up, if it crashes regually pm2 has no use, you need to fix your server.

Come to think of it, also check if that request taking too much resources to process, if system get out of resources it will kill your process.

Dunigan answered 20/11, 2019 at 14:8 Comment(1)
Hey I use 4 clusters of my node server on pm2. Can this happen because I the machine is not able to handle 4 clusters ?Entrain

© 2022 - 2024 — McMap. All rights reserved.