Node-Red crashes on start, all flows down!

I was updating some flows and doing what I normally do, hit deploy and it never returned. I am now getting the following in my logs.

18 Feb 00:37:25 - [info] Starting flows

<--- Last few GCs --->

[1103:0x7f8acf1d9020]    25362 ms: Mark-sweep 1854.7 (2095.8) -> 1851.2 (2092.5) MB, 184.6 / 0.0 ms  (average mu = 0.190, current mu = 0.138) allocation failure; GC in old space requested
[1103:0x7f8acf1d9020]    25583 ms: Mark-sweep 1856.6 (2095.8) -> 1853.0 (2092.5) MB, 192.7 / 0.0 ms  (average mu = 0.160, current mu = 0.129) allocation failure; GC in old space requested


<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
[00:37:50] INFO: Service Node-RED exited with code 256 (by signal 6)
[00:37:51] INFO: Starting Node-RED...

If you have a recent backup of NR then you could restore that to get it to come back up. You would lose your most recent flows, but at least you would restore access again.

The error message comes from the V8 Javascript engine that powers Node-RED, complaining that it has run out of heap memory.

This is fatal and can only result in Node-RED stopping.

The likely cause is a non terminating loop. As this appears to happen just 25 seconds after a Node-RED restart, I would assume also that the loop is allocating a large data item on each iteration.

JS heap memory is quite small, and it is possible to request more in the Node-RED startup settings. This might just give enough time to get to the problematic flow and disable it, although I am inclined to think that a better option is to start Node-RED in safe mode and work on the flow that way.

If you can start Node-RED in safe mode, all flows are disabled, and this will allow you to edit the problem flow to remove the loop before restarting as usual.

  1. Backup hass
  2. Unzip file backup
  3. Find file flows.json (all flows of node-red)
  4. Remove node-red addon
  5. Connect SSH to HASS => cd to addons_config => Remove node-red folder
  6. Install node-red addon
  7. Import file flows.json (step3) to new node-red

Good luck!