Node-Red..FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed

I’ve run out of Memory access in HA Node-red intergration.
Was previously using HA in a windows virtual box, had the same issue but fixed it by typing in the termanal:➜ /config git:(master) ✗ set NODE_OPTIONS=--max-old-space-size=8192

Today I have moved from the testing VM onto a laptop for headless permant install using x86_64 HA build. (Details Below)
|Version|core-2022.2.5|
|Installation Type|Home Assistant OS|
|Development|false|
|Supervisor|true|
|Docker|true|
|User|root|
|Virtual Environment|false|
|Python Version|3.9.7|
|Operating System Family|Linux|
|Operating System Version|5.10.91|
|CPU Architecture|x86_64|

  • 8GB RAM.
  • 128GB SSD

Everything went ok, Installed NR from the HA Add-on store. Checked logs then imported existing Flow.
But the Node-Red Fatal error returned, so I tried this in the Studio Code Server Termanal again like last time in the VM:
set NODE_OPTIONS=--max-old-space-size=5000 as I only have 8GB in the laptop.

Restarted core, supervisor & host thou nothing I do seems to allow it to allocate just a bit more space past the Node-Red default old_space_size of just less than 2GB, I require 2.3GB no more.

New install, everything is default, thou I have added in NR settings.js:

    default: { module: 'memory' },
    file: { module: 'localfilesystem' }
},
};

Anyone know how to expand the limit or fix this issue using HA node-red?
I am wanting to “expand the default limit”, not start a new flows.json or alike.

Thanks in advanced :slight_smile:

LOG___________________________________

[569:0x7f7215447330]    48701 ms: Scavenge (reduce) 1931.4 (2083.1) -> 1930.8 (2083.3) MB, 10.2 / 0.0 ms  (average mu = 0.101, current mu = 0.030) allocation failure 
[569:0x7f7215447330]    51799 ms: Mark-sweep (reduce) 1932.2 (2083.8) -> 1921.4 (2083.8) MB, 3070.6 / 0.3 ms  (average mu = 0.198, current mu = 0.290) allocation failure scavenge might not succeed
<--- JS stacktrace --->
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory```
___________________________________

I have made some progress here, using linux (HA) the command I referanced above ‘set’ is for windows node-red… so this is what I have so far to fix/reproduce.

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

HA in the HA add-on ‘Studio Code Server’ (or whatever your flavor)
Open up a - Termanal
(Top Righthand icon 3 horizontal lines (scroll to Terminal/New Terminal.

(LINUX or HA) ‘export’
TYPE: ‘node-red’ (Press Enter - should switch line to node-red)
TYPE: ‘export’ (Press Enter - should spam (look for ‘NODE_OPTIONS=’–max-old-space-size=2048 ‘’)
TYPE: export NODE_OPTIONS=–max-old-space-size=8192 (Press Enter - 8192 is MB(or 8GB)to allocate - assign more or less per your requirements)
TYPE: export (Press Enter, should spam (look for ‘NODE_OPTIONS=’–max-old-space-size=8192 ‘’)

(WINDOWS OS) ‘set’
TYPE: ‘node-red’ (Press Enter)
TYPE: ‘set NODE_OPTIONS=–max-old-space-size=8192’

So I now see it is updated in export, just need it to save there as after reboot it reverts back to default 2048.

OK github suggested this before closing topic:
sinclairpaul commented 20 minutes ago

Looks as if you are setting the environment variable via Code Server, which is running in a separate container.

It’s likely you could do this either using the Init Commands option, or by specifying the Environment Variable, both of which are in the documentation.

For configuration help I would suggest using Discord or the forums.


So just need to work out how to do this!!

On the addon the re is a config tab, in that section under init_commands you can run a command during startup. env_variables are defined in settings.js in the nodered folder.

I tried many things & hours reading many documents on this, just dont know how, during startup. env_variables would be written.

In the settings.js I tried this.

  editorTheme: {
    projects: {
      // To enable the Projects feature, set this value to true
      enabled: false,
    },
  },
  contextStorage: {
    default: { module: 'memory' },
    file: { module: 'localfilesystem' }
  },
  NODE_OPTIONS:"--max-old-space-size=4007",
}; 

In the Node-RED configuration I tried adding this:

init_commands:
  - NODE_OPTIONS="--max_old_space_size=4013" nodered/node-red

I don’t know, I must be close?

Even though it’s in a windows vm, the operating environment I believe is still linux.
try it with export, I mean try set as well but I do think it’s linux.

init_commands:
  - export NODE_OPTIONS=--max_old_space_size=4096

I was using a windows VM,
now:
|Operating System Family|Linux|
|Operating System Version|5.10.91|
|CPU Architecture|x86_64|

But I’ll try the above now ty

<--- Last few GCs --->
[515:0x7fca8655e330]    64431 ms: Scavenge (reduce) 1927.7 (2083.0) -> 1927.0 (2083.0) MB, 11.5 / 0.0 ms  (average mu = 0.250, current mu = 0.372) allocation failure 
[515:0x7fca8655e330]    64521 ms: Scavenge (reduce) 1927.8 (2083.0) -> 1927.1 (2083.0) MB, 11.2 / 0.0 ms  (average mu = 0.250, current mu = 0.372) allocation failure 
[515:0x7fca8655e330]    64607 ms: Scavenge (reduce) 1928.0 (2083.0) -> 1927.2 (2083.0) MB, 11.1 / 0.0 ms  (average mu = 0.250, current mu = 0.372) allocation failure 
<--- JS stacktrace --->
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
[06:56:50] INFO: Starting Node-RED...

no joy :cry: Still capped to less than 2000

The docs show quotes around the command.

export NODE_OPTIONS="--max_old_space_size=4096"

What is the os environment it is running in now? If it’s docker or something similar you may need to increase the memory allocated to the container as well as nodered.

Yeah I read that also and tried that, but to no progression, sorry.

This is installed on a dedicated laptop.

This is installed on a Laptop, dedicated just to run HA UEFI boot like didn’t think be such a hassel…

During the HA install I just flashed HA using etcher onto the SSD and HA started,
IDK but I think HA runs in in a docker as when I go to HA UI Configuration/Settings/Info it does say “Docker=true”.
Would you know how I do incress this?


IDK if this is the right screen but refreshing this during NR start up nothing seems high usage.

Try in settings.js right right under

process.env.HOSTNAME = require('os').hostname();

add

process.env.NODE_OPTIONS="--max_old_space_size=4096"

OK, so as of Node-Red 11.0.0 released last night, there is now an option in the configuration file. Many thanks to Frenck for this!

The solution for me was to Update to HA Node-Red v11.0.0 add-on, then add amount required in the config (Photo Attached).

If you are reading this in the future, please keep in mind this is not a solution should you have a memory leak, this is not a long-term fix for that… and this option should only be used be for when you understand that it is not a leak. and require some more system oomph.

By increasing it assisted me to mot only get Node-Red to load again but increased the “Deploy” (reload) time back to where it was originally on an empty flow, as Re-Deploy had been slowing down prior for months prior to the crash.

1 Like