PM2 Crash allocation failure
After very long and reliable duty (almost year), today pm2 crashed itself twice.
pm2 1.0.0 node v4.2.4 free -h reports that server has 1GB of free memory.
from pm2.log
FATAL ERROR: Committing semi space failed. Allocation failed - process out of memory
<--- Last few GCs --->
11077620 ms: Scavenge 17.8 (54.9) -> 16.8 (54.9) MB, 5.8 / 0 ms [allocation failure].
11107284 ms: Scavenge 17.8 (54.9) -> 17.0 (54.9) MB, 1.1 / 0 ms [allocation failure].
11137818 ms: Scavenge 17.9 (54.9) -> 17.0 (54.9) MB, 13.0 / 0 ms [allocation failure].
11197344 ms: Scavenge 17.9 (54.9) -> 17.0 (54.9) MB, 602.4 / 2 ms [allocation failure].
11360431 ms: Scavenge 18.0 (54.9) -> 17.1 (54.9) MB, 1218.8 / 0 ms [allocation failure].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x2aa6137b4629 <JS Object>
1: safeDeepClone(aka safeDeepClone) [/usr/lib/node_modules/pm2/lib/tools/safeclonedeep.js:53] [pc=0x1697ae06b47] (this=0x2aa6137041b9 <undefined>,circularValue=0x2aa6137041b9 <undefined>,refs=0x103f0c0b81f1 <JS Array[2]>,obj=0x3cccfce76c09 <a ChildProcess with map 0x3440658a0d59>)
2: safeDeepClone(aka safeDeepClone) [/usr/lib/node_modules/pm2/lib/tools/safeclonedeep.js:53] [pc=0x1697ae0..
@mauron85 Maybe more log available? Full JS Stack trace is most interesting thing.
Thats' all from pm2.log. I didn't trimmed stack trace, it was saved that way.
@mauron85 Well, there are many places where safedeepclone.js is used.
/cc @Unitech @soyuka
indeed and a lot of aliases too
@mauron85 Any data like graphs of memory usage by certain processes (PM2 or all on the host) through the year? So we'd know if it's a kind of slow leak or fast which happens in some conditions and PM2 starts leaking.
@estliberitas I'am ashamed but none :-). That's our dev server. I though I've found lead, but it turned out to be false positive. I've configured (by mistake) pm2 to store pids into /var/run/somedir dir, which worked until restart. Then pm2 start filling logs about unable to put pids to that dir and then crashed. I've reconfigured pm2 to store pids into it's own dir, but after couple of hours it crashed again with same error. So it was not related.
EDIT: I can enable some kind of monitoring, but to be honest, I don't know what of kind of sw use for this purpose.
EDIT2: Server is running for almost year, but must time pm2 was version before 1.0 (not sure about the exact number). Now it's 1.0.0
It crashed once again. The crash dump is trimmed. Maybe I can raise limit by ulimit -c, but I'm not sure how to use it.
Anyway I also installed pm2-server-monit and start logging into keymetrics. I'm curious.
@mauron85 Uhm, interesting. Isn't it somehow connected with cluster mode? What is Node.js version?
@estliberitas All apps are in fork mode (this is just dev server). And node is v4.2.6. But the more I think about it, the more I think that it's not probably pm2 related thing.
But even it's server related, the strange thing is that pm2 completely forget it's configuration and I have to configure it with pm2 start pm2.json
the strange thing is that pm2 completely forget it's configuration and I have to configure it with pm2 start pm2.json
@mauron85 more details plz
after crash when I exec pm2 list. The list of apps is empty. So I have to start them all again with pm2 start
@mauron85 Even with pm2 dump?
Typical case would be:
$ pm2 start ...$ pm2 dump- PM2 dies
$ pm2 resurrect
Will try next time it crashes. But what is the actual diferrence? I mean it doesn't matter if I have to pm2 resurrect or pm2 start. My conf is already in json, that I created manually.
You're correct. The only difference is once it dies you can call one command and that's all. Also, when you do pm2 list if I'm correct PM2 is just spawned (if not already) without resurrect action. Btw would be cool to auto-resurrect.
Let guys correct me if I'm wrong: /cc @Unitech @soyuka
+1 for auto-resurrect. It would make a difference. ;-)
@estliberitas It just happened again . However I don't have access to logs in free acount. Do you? https://app.keymetrics.io/#/bucket/56a3eda17340c1a186aa5f9a/dashboard
So it seems, when pm2 master process dies because of out memory, it "forgets" configuration settings.
016-03-01 23:39:58: App name:pm2-server-monit id:0 online
<--- Last few GCs --->
1164486245 ms: Scavenge 12.7 (52.9) -> 11.9 (52.9) MB, 1036.2 / 1 ms [allocation failure].
1164495996 ms: Scavenge 12.8 (52.9) -> 12.0 (52.9) MB, 405.3 / 0 ms [allocation failure].
1164508584 ms: Scavenge 12.8 (52.9) -> 12.0 (52.9) MB, 1820.5 / 0 ms [allocation failure].
1164525690 ms: Scavenge 12.9 (52.9) -> 12.1 (52.9) MB, 18.0 / 0 ms [allocation failure].
1164594147 ms: Scavenge 13.3 (52.9) -> 12.4 (52.9) MB, 2436.6 / 394 ms (+ 6348.9 ms in 11 steps since last GC) [allocation failure].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x214942db4629 <JS Object>
1: safeDeepClone(aka safeDeepClone) [/usr/lib/node_modules/pm2/lib/tools/safeclonedeep.js:48] [pc=0x266254f80336] (this=0x214942d041b9 <undefined>,circularValue=0x214942d041b9 <undefined>,refs=0x2757610d02c1 <JS Array[3]>,obj=0xd513ade60c1 <a Socket with map 0x226d2c5a6711>)
2: safeDeepClone(aka safeDeepClone) [/usr/lib/node_modules/pm2/lib/tools/safeclonedeep.js:53] [pc=0x266254f80578]...
FATAL ERROR: Committing semi space failed. Allocation failed - process out of memory
It crashed again. This time systat confirmed that pm2 crashes due out of memory. Here is correlation of pm2.log crash log entry and sar -u output.
The _interesting_ thing here is that memory consumption is on average 33% for whole day and only start to rise at midnight, which is time when pm2 is scheduled to restart services (option cron_restart": "1 0 * * *")
Is there any debug option in pm2, to see what's going on?
pm2.log
2016-03-05 01:50:43: App name:pm2-server-monit id:0 online
<--- Last few GCs --->
98837666 ms: Scavenge 15.5 (51.9) -> 14.6 (51.9) MB, 41.3 / 0 ms [allocation failure].
98839131 ms: Scavenge 15.4 (51.9) -> 14.6 (51.9) MB, 207.3 / 0 ms [allocation failure].
98843277 ms: Scavenge 15.5 (51.9) -> 14.6 (51.9) MB, 5.5 / 0 ms [allocation failure].
98845923 ms: Scavenge 15.5 (51.9) -> 14.7 (51.9) MB, 1.9 / 0 ms [allocation failure].
98857939 ms: Scavenge 15.6 (51.9) -> 14.7 (51.9) MB, 1600.0 / 7 ms [allocation failure].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x3736a16b4629 <JS Object>
2: safeDeepClone(aka safeDeepClone) [/usr/lib/node_modules/pm2/lib/tools/safeclonedeep.js:53] [pc=0x2440e580c67] (this=0x3736a16041b9 <undefined>,circularValue=0x3736a16041b9 <undefined>,refs=0x2c69700dbb41 <JS Array[4]>,obj=0x35def99d4559 <an Object with map 0x6e0207b30d9>)
3: safeDeepClone(aka safeDeepClone) [/usr/lib/node_modules/pm2/lib/tools/safeclonedeep.js:53] [pc=0x2440e580c58] ...
FATAL ERROR: Committing semi space failed. Allocation failed - process out of memory
sar -r
12:00:01 AM kbmemfree kbmemused %memused kbbuffers kbcached kbcommit %commit kbactive kbinact kbdirty
11:55:01 PM 1049100 667692 38.89 96356 306776 427312 24.89 404476 142652 8
11:59:01 PM 1047492 669300 38.99 96376 306804 424980 24.75 405888 142652 8
12:00:01 AM 1048812 667980 38.91 96376 306808 426724 24.86 404660 142652 8
12:05:02 AM 316412 1400380 81.57 111112 600172 1245716 72.56 1029184 210044 24
12:15:01 AM 222972 1493820 87.01 111112 600332 1318968 76.83 1122684 210044 20
12:25:01 AM 161864 1554928 90.57 111112 600480 1403392 81.75 1183632 210044 32
12:35:01 AM 114560 1602232 93.33 110768 563236 1473716 85.84 1169672 271260 16
12:45:01 AM 146716 1570076 91.45 108344 423920 1578836 91.96 1144232 265648 20
12:55:01 AM 101500 1615292 94.09 84156 403772 1688544 98.35 1225116 230120 12
01:05:01 AM 129432 1587360 92.46 40552 296292 1756992 102.34 1263124 167956 56
01:15:01 AM 116580 1600212 93.21 34504 255644 1867204 108.76 1306024 139236 72
01:25:01 AM 123952 1592840 92.78 22276 135596 1967508 114.60 1373384 77876 48
01:35:01 AM 114312 1602480 93.34 8760 79964 2066776 120.39 1434340 42304 60
01:45:01 AM 100724 1616068 94.13 1048 62868 2161336 125.89 1483480 24932 52
01:56:04 AM 90688 1626104 94.72 172 9100 2139948 124.65 1516096 4796 4
02:05:02 AM 1400552 316240 18.42 5312 77632 422240 24.59 170784 50772 68
Configuration pm2.json
I have same problem.
I also have the same problem