Memory leakage of Node-Red on RasPI

Edit: 14Jun18
I apologize, this response and the one below really belong in this thread: Memory leak, what am I doing wrong?
I wasn’t paying close enough attention when I saw the topic and krambris’s asking about my flow … I thought it was in my thread. _

I can post the flow easy enough, but without my hardware It can’t really do anything. The only objects I write or modify are with change nodes and most of this is in the second flow that does the notification if the AI has made a detection and the system is in notify mode. Its why I originally asked if I need to do anything more than return null when a msg.payload buffer message comes it to drop it and clean up in a function node.

The upgrade to nodejs v4.9.1 helped, but it died and restarted again about 15 minutes ago, this had run for a bit over two days and the time from the error to flow running again was something like 12 seconds, its not a very significant issue to have 12 seconds of missed monitoring in ~50 hours, especially considering that my Lorex DVR has about 5 seconds latency from a trigger to the first snapshot received.

From syslog it seems pretty clear what is happening – out of memory in node-red-contrib-ftp-server when a snapshot comes in, node-red dies, I get my MQTT “will” message and it restarts and all is well until the cycle repeats. Not perfect but usable. I was going to use the will message to restart node-red via another monitoring process but systemd seems to handle it automatically and very fast! I’m beginning to see the merits in the switch to systemd, up to now a “controversy” that seemed mostly philosophical to me – shell scripts vs binary blobs controlling the system, about with I could care less as long as it worked!

Here is the most recent relevant syslog:

Jun 8 10:34:59 alarmPi Node-RED[25524]: 8 Jun 10:34:58 - [red] Uncaught Exception:
Jun 8 10:34:59 alarmPi Node-RED[25524]: 8 Jun 10:34:59 - RangeError: Invalid array buffer length
Jun 8 10:34:59 alarmPi Node-RED[25524]: at new ArrayBuffer (native)
Jun 8 10:34:59 alarmPi Node-RED[25524]: at new Uint8Array (native)
Jun 8 10:34:59 alarmPi Node-RED[25524]: at createBuffer (buffer.js:25:17)
Jun 8 10:34:59 alarmPi Node-RED[25524]: at allocate (buffer.js:166:12)
Jun 8 10:34:59 alarmPi Node-RED[25524]: at new Buffer (buffer.js:56:12)
Jun 8 10:34:59 alarmPi Node-RED[25524]: at Socket.dataHandler (/home/pi/.node-red/node_modules/ftpd/lib/ftpd.js:1413:27)
Jun 8 10:34:59 alarmPi Node-RED[25524]: at emitOne (events.js:77:13)
Jun 8 10:34:59 alarmPi Node-RED[25524]: at Socket.emit (events.js:169:7)
Jun 8 10:34:59 alarmPi Node-RED[25524]: at readableAddChunk (_stream_readable.js:153:18)
Jun 8 10:34:59 alarmPi Node-RED[25524]: at Socket.Readable.push (_stream_readable.js:111:10)
Jun 8 10:34:59 alarmPi Node-RED[25524]: at TCP.onread (net.js:540:20)
Jun 8 10:35:00 alarmPi systemd[1]: nodered.service: Main process exited, code=exited, status=1/FAILURE
Jun 8 10:35:00 alarmPi systemd[1]: nodered.service: Unit entered failed state.
Jun 8 10:35:00 alarmPi systemd[1]: nodered.service: Failed with result ‘exit-code’.
Jun 8 10:35:00 alarmPi systemd[1]: nodered.service: Service hold-off time over, scheduling restart.
Jun 8 10:35:00 alarmPi systemd[1]: Stopped Node-RED graphical event wiring tool.
Jun 8 10:35:00 alarmPi systemd[1]: Started Node-RED graphical event wiring tool.
Jun 8 10:35:04 alarmPi Node-RED[27073]: 8 Jun 10:35:04 - [info]
Jun 8 10:35:04 alarmPi Node-RED[27073]: Welcome to Node-RED
Jun 8 10:35:04 alarmPi Node-RED[27073]: ===================
Jun 8 10:35:04 alarmPi Node-RED[27073]: 8 Jun 10:35:04 - [info] Node-RED version: v0.18.7
Jun 8 10:35:04 alarmPi Node-RED[27073]: 8 Jun 10:35:04 - [info] Node.js version: v4.9.1
Jun 8 10:35:04 alarmPi Node-RED[27073]: 8 Jun 10:35:04 - [info] Linux 4.14.34-v7+ arm LE
Jun 8 10:35:05 alarmPi Node-RED[27073]: 8 Jun 10:35:05 - [info] Loading palette nodes
Jun 8 10:35:11 alarmPi Node-RED[27073]: 8 Jun 10:35:11 - [warn] ------------------------------------------------------
Jun 8 10:35:11 alarmPi Node-RED[27073]: 8 Jun 10:35:11 - [warn] [node-red-node-serialport/serialport] Error: Module version mismatch. Expected 46, got 57.
Jun 8 10:35:11 alarmPi Node-RED[27073]: 8 Jun 10:35:11 - [warn] ------------------------------------------------------
Jun 8 10:35:11 alarmPi Node-RED[27073]: 8 Jun 10:35:11 - [info] Settings file : /home/pi/.node-red/settings.js
Jun 8 10:35:11 alarmPi Node-RED[27073]: 8 Jun 10:35:11 - [info] User directory : /home/pi/.node-red
Jun 8 10:35:11 alarmPi Node-RED[27073]: 8 Jun 10:35:11 - [warn] Projects disabled : set editorTheme.projects.enabled=true to enable
Jun 8 10:35:11 alarmPi Node-RED[27073]: 8 Jun 10:35:11 - [info] Flows file : /home/pi/.node-red/flows_alarmPi.json
Jun 8 10:35:11 alarmPi Node-RED[27073]: 8 Jun 10:35:11 - [info] Server now running at http://127.0.0.1:1880/

I may try reducing the max_old_space_size parameter in hopes of maybe being more aggressive with garbage collection, and I may try upgrading nodejs to 6.x (the last that should work with the ftp-server node).

But actually I’ve bigger fish to fry at the moment with regards to they system that are Android issues – I’m not reliably getting timely Email notifications on my Android 7.0 phone, sometimes they are near instant, other times 10 to 20 or more minutes late which is potentially a much bigger issue than having the AI off for 12 seconds every ~50 hours. Another issue is my “backup” notification node-red on Termux-API sending SMS messages to prompt me to check Email running on a cheap Blu Android 6.x phone dies every 2-3 weeks and needs to be rebooted or it automatically reboots and hangs until I dismiss a dialog.

So I think we can put this to bed until node-red-contrib-ftp-server gets fixed, if ever, to work with 8.x and newer versions of nodejs