Node-Red crashes due to memory leak

Hello! I hope I get can some help in solving this problem I have with Node-Red!
Up till 3 weeks ago, I was running Node-Red V0.2.x perfectly on my Raspberry Pi4 without any problems.

However, after that, the terminal I use to run Node-Red started giving me MaxListenersExceededWarning: Possible EventEmitter memory leak detected. errors.
Naturally, I looked up the error and many forums stated it's just a warning so I wasn't too concerned.

Around 2 weeks back, as I was using Node-Red, the web page would start losing connection to the server, and when I checked the terminal again it would give me these errors with different Node IDs every time.


Welcome to Node-RED
===================
2 Dec 10:19:16 - [info] Node-RED version: v1.0.3
2 Dec 10:19:16 - [info] Node.js  version: v12.13.1
2 Dec 10:19:16 - [info] Linux 4.19.75-v7l+ arm LE
2 Dec 10:19:16 - [info] Loading palette nodes
2 Dec 10:19:18 - [info] Dashboard version 2.18.0 started at /ui
2 Dec 10:19:18 - [info] Settings file  : /home/pi/.node-red/settings.js
2 Dec 10:19:18 - [info] Context store  : 'default' [module=memory]
2 Dec 10:19:18 - [info] User directory : /home/pi/.node-red
2 Dec 10:19:18 - [warn] Projects disabled : editorTheme.projects.enabled=false
2 Dec 10:19:18 - [info] Flows file     : /home/pi/.node-red/flows_raspberrypi.json
2 Dec 10:19:18 - [info] Server now running at http://127.0.0.1:1880/
2 Dec 10:19:18 - [warn]
---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.
If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.
You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------
2 Dec 10:19:18 - [info] Starting flows
2 Dec 10:19:18 - [info] Started flows
(node:2431) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 ready listeners added to [Firmata]. Use emitter.setMaxListeners() to increase limit
(node:2431) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 ready listeners added to [Firmata]. Use emitter.setMaxListeners() to increase limit
(node:2431) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 ready listeners added to [Firmata]. Use emitter.setMaxListeners() to increase limit
<--- Last few GCs --->
[2431:0x1fbc620]   119748 ms: Scavenge 253.9 (257.2) -> 252.5 (261.4) MB, 12.3 / 0.0 ms  (average mu = 0.295, current mu = 0.287) allocation failure
[2431:0x1fbc620]   121826 ms: Mark-sweep 253.6 (261.4) -> 253.4 (255.9) MB, 1339.2 / 0.1 ms  (+ 591.2 ms in 1272 steps since start of marking, biggest step 7.5 ms, walltime since start of marking 2078 ms) (average mu = 0.249, current mu = 0.194) finalize
<--- JS stacktrace --->
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
nodered.service: Main process exited, code=killed, status=6/ABRT
nodered.service: Failed with result 'signal'.
nodered.service: Service RestartSec=100ms expired, scheduling restart.
nodered.service: Scheduled restart job, restart counter is at 10.
Stopped Node-RED graphical event wiring tool.
Started Node-RED graphical event wiring tool.

Updating Nodejs, NPM and Node-red did nothing.
I tried using the max_old_space_size command but that didn't work too.
I believe it's not a problem with the version but one of the nodes ( I suspect the Arduino nodes).
Here's a picture of my nodes.

How do I solve this issue? Thank you!!

This appears to be caused by the arduino nodes.
Did you check if there is an update available for the arduino nodes ?

hamburger menu -> manage palette
check for updates for each node.

Hi, the nodes are of the latest version (3.0.0) but the 'arduino-board' node is grey while the 2 other nodes (arduino in/arduino out) are green.

I'm afraid that you will have to contact the author.

Node.js  version: v12.13.1

That might be the issue though. I don't think everyone has updated their nodes to work with node.js v12 as yet. You could try with node.js v10 instead?

Thanks for your suggestion! I managed to downgrade NodeJS to v10.17.0 and the memory leak errors were gone! In Node-red, I had to delete the unknown nodes in Configuration Nodes as well. Node-Red runs well now! Thanks!!

Please file an issue on the node's github page so that others will see the issue and also so that it might get fixed.

Alright I will! I'm reporting node-red-node-arduino as the cause of the issue right?

Go to that node's GitHub page (it should be linked to from the nodes npm page) and create an issue with the information you posted above and describing how you got round it.

I updated the arduino node to not warn about event emitters, and tested it on node12. No problem so far.

1 Like

I don't understand what you mean by that, why did downgrading nodejs mean there were unused config nodes?

Oh wait deleting the nodes was for another issue I had sorry about that, I'll remove it.
I submitted an issue on GitHub and @dceejay has already fixed it :slight_smile:

It is a V8 bug and Google has just fixed it, see my detailed analysis https://gist.github.com/likev/2521f6cde21215e8fe6f53d4c6370fa8