Very long GC pauses when NodeJS is about to die from memory exhaustion

(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com

I sometimes see stuff like this in my logs, when my NodeJS app has reached critical:

<--- Last few GCs --->

  856870 ms: Mark-sweep 5647.1 (6029.8) -> 5625.8 (6029.8) MB, 10733.9 / 0.0 ms [allocation failure] [GC in old space requested].
  867774 ms: Mark-sweep 5625.8 (6029.8) -> 5625.8 (6030.8) MB, 10903.4 / 0.0 ms [allocation failure] [GC in old space requested].
  878580 ms: Mark-sweep 5625.8 (6030.8) -> 5625.8 (5996.8) MB, 10806.3 / 0.0 ms [last resort gc].
  889353 ms: Mark-sweep 5625.8 (5996.8) -> 5625.8 (5996.8) MB, 10773.0 / 0.0 ms [last resort gc].

<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x1b2594dcfb51 
    1: DoJoin(aka DoJoin) [native array.js:~129] [pc=0x432db260a69] (this=0x1b2594d04381 ,w=0x19cc4da897b9 ,x=68277,N=0x1b2594d043c1
,J=0x231615ef899 ,I=0x1b2594db46e1 )
    2: Join(aka Join) [native array.js:180] [pc=0x432db381812] (this=0x1b2594d04381 ,w=0x19cc4da89...

These pauses can last for 20 or 30 minutes.

I have my NodeJs app setup so it can be restarted by Supervisord. Sadly, these long pauses mean the NodeJS app is non-responsive, but Supervisord won’t kill it because enough clients get through.

Source