High CPU usage & out of memory

Hi, I've got problem where the node-red service have almost 95-100% cpu usage and eventually restart it self. Here's what I've got from syslog:

node-red[5886]: (Use `node --trace-deprecation ...` to show where the warning was created)
node-red[5886]: 21 Aug 00:26:43 - [info]
node-red[5886]: Welcome to Node-RED
node-red[5886]: ===================
node-red[5886]: 21 Aug 00:26:43 - [info] Node-RED version: v2.0.5
node-red[5886]: 21 Aug 00:26:43 - [info] Node.js  version: v16.6.2
node-red[5886]: 21 Aug 00:26:43 - [info] Linux 4.9.0-16-amd64 x64 LE
node-red[5886]: 21 Aug 00:26:43 - [info] Loading palette nodes
node-red[5886]: 21 Aug 00:26:44 - [info] Settings file  : /root/.node-red/settings.js
node-red[5886]: 21 Aug 00:26:44 - [info] Context store  : 'default' [module=memory]
node-red[5886]: 21 Aug 00:26:44 - [info] User directory : /root/.node-red
node-red[5886]: 21 Aug 00:26:44 - [warn] Projects disabled : editorTheme.projects.enabled=false
node-red[5886]: 21 Aug 00:26:44 - [info] Flows file     : /root/.node-red/flows.json
node-red[5886]: 21 Aug 00:26:45 - [info] Server now running at http://127.0.0.1:1880/
node-red[5886]: 21 Aug 00:26:45 - [warn]
node-red[5886]: ---------------------------------------------------------------------
node-red[5886]: Your flow credentials file is encrypted using a system-generated key.
node-red[5886]: If the system-generated key is lost for any reason, your credentials
node-red[5886]: file will not be recoverable, you will have to delete it and re-enter
node-red[5886]: your credentials.
node-red[5886]: You should set your own key using the 'credentialSecret' option in
node-red[5886]: your settings file. Node-RED will then re-encrypt your credentials
node-red[5886]: file using your chosen key the next time you deploy a change.
node-red[5886]: ---------------------------------------------------------------------
node-red[5886]: 21 Aug 00:26:45 - [info] Starting flows
node-red[5886]: 21 Aug 00:26:45 - [info] Started flows
node-red[5886]: <--- Last few GCs --->
node-red[5886]: [5886:0x52a0cd0]   101132 ms: Mark-sweep (reduce) 254.6 (260.7) -> 253.8 (260.9) MB, 554.5 / 0.3 ms  (average mu = 0.233, current mu = 0.175) allocation failure scavenge might not succeed
node-red[5886]: [5886:0x52a0cd0]   101808 ms: Mark-sweep (reduce) 255.3 (261.4) -> 254.1 (261.7) MB, 558.5 / 0.3 ms  (average mu = 0.205, current mu = 0.174) allocation failure scavenge might not succeed
node-red[5886]: <--- JS stacktrace --->
node-red[5886]: FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
node-red[5886]:  1: 0xafedf0 node::Abort() [node-red]
node-red[5886]:  2: 0xa1814d node::FatalError(char const*, char const*) [node-red]
node-red[5886]:  3: 0xce792e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node-red]
node-red[5886]:  4: 0xce7ca7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node-red]
node-red[5886]:  5: 0xeb1685  [node-red]
node-red[5886]:  6: 0xec081d v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node-red]
node-red[5886]:  7: 0xec399c v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node-red]
node-red[5886]:  8: 0xe862bc v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node-red]
node-red[5886]:  9: 0x11f3126 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node-red]
node-red[5886]: 10: 0x15c9eb9  [node-red]
systemd[1]: node-red.service: Main process exited, code=killed, status=6/ABRT
systemd[1]: node-red.service: Unit entered failed state.
systemd[1]: node-red.service: Failed with result 'signal'.
systemd[1]: node-red.service: Service hold-off time over, scheduling restart.
systemd[1]: Stopped Node-RED.
systemd[1]: Started Node-RED.
node-red[5920]: (node:5920) [DEP0128] DeprecationWarning: Invalid 'main' field in '/usr/lib/node_modules/node-red/node_modules/@node-red/editor-client/package.json' of './lib/index.js'. Please either fix that or report it to the module author
node-red[5920]: (Use `node --trace-deprecation ...` to show where the warning was created)
node-red[5920]: 21 Aug 00:28:25 - [info]
node-red[5920]: Welcome to Node-RED

It's running on 1GB VPS with explicit --max_old_space_size=256 option. The system memory is fine (I think), it got ~600MB free left. I've influxdb, blynk & email node installed. I thought maybe there is some problem with one of the node, but when I disabling all flows the problem is still there, keep restarting every 1-2 min. From the process-monitor I've got this behavior, first the CPU goes up to almost 100%, then the memory climbing up from 0 to around 256MB then restarted.

Any suggestion where do I needed to take a look?

Try starting node-red with the --safe flag.

node-red --safe

Check your flows for loops.
Perhaps install the new flow linter to help you.

Also, if you are using MQTT, are you subscribing to a topic that you then modify? This is a common mistake that causes a loop.

I would get rid of that. Modern versions of Node.js rarely need help steering their memory use any more even on quite restricted platforms. It is likely to more harm than good.

Have you seen the FAQ I wrote yesterday regarding memory analysis?

Also, I assume that you don't have the problem if you don't start Node-RED?

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.