Node-RED stuck in infinite crash loop

Node-RED is stuck in a constant crash loop and I’m not completely clear why. I’m able to run Node-RED in Safe Mode. But other than that the log isn’t particularly clear to me. What could be causing the issue exactly?

This appears to be the main error causing the crash.

13 Jun 19:53:49 - [error] Error: JSONata Error: Argument 1 of function "contains" does not match function signature
    at EventsState.getComparatorResult (/config/node-red/node_modules/node-red-contrib-home-assistant-websocket/dist/nodes/BaseNode.js:241:27)
    at EventsState.onHaEventsStateChanged (/config/node-red/node_modules/node-red-contrib-home-assistant-websocket/dist/nodes/events-state/controller.js:71:32)
    at EventsState.onStatesLoaded (/config/node-red/node_modules/node-red-contrib-home-assistant-websocket/dist/nodes/events-state/controller.js:179:18)
    at EventEmitter.emit (node:events:539:35)
    at /config/node-red/node_modules/node-red-contrib-home-assistant-websocket/dist/homeAssistant/Websocket.js:223:27

Here’s the full log up to the point where NR crashes and reboots.

Flow-based programming for the Internet of Things
-----------------------------------------------------------
 Add-on version: 12.0.2
 You are running the latest version of this add-on.
 System: Home Assistant OS 8.1  (amd64 / qemux86-64)
 Home Assistant Core: 2022.6.5
 Home Assistant Supervisor: 2022.05.3
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
cont-init: info: /etc/cont-init.d/00-banner.sh exited 0
cont-init: info: running /etc/cont-init.d/01-log-level.sh
cont-init: info: /etc/cont-init.d/01-log-level.sh exited 0
cont-init: info: running /etc/cont-init.d/customizations.sh
cont-init: info: /etc/cont-init.d/customizations.sh exited 0
cont-init: info: running /etc/cont-init.d/nginx.sh
cont-init: info: /etc/cont-init.d/nginx.sh exited 0
cont-init: info: running /etc/cont-init.d/node-red.sh
patching file nodes/ui_base.html
Hunk #1 succeeded at 1164 (offset 633 lines).
[19:53:26] WARNING: 
[19:53:26] WARNING: Direct access mode is disabled, Node-RED Dashboard
[19:53:26] WARNING: will not work!
[19:53:26] WARNING: 
[19:53:26] WARNING: Please assign a port in the Network section of this
[19:53:26] WARNING: add-on configuration.
[19:53:26] WARNING: 
up to date, audited 727 packages in 11s
1 package is looking for funding
  run `npm fund` for details
31 vulnerabilities (5 moderate, 21 high, 5 critical)
To address issues that do not require attention, run:
  npm audit fix
Some issues need review, and may require choosing
a different dependency.
Run `npm audit` for details.
cont-init: info: /etc/cont-init.d/node-red.sh exited 0
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
services-up: info: copying legacy longrun nginx (no readiness notification)
services-up: info: copying legacy longrun nodered (no readiness notification)
s6-rc: info: service legacy-services successfully started
[19:53:38] INFO: Starting Node-RED...
> start
> node $NODE_OPTIONS node_modules/node-red/red.js "--settings" "/etc/node-red/config.js"
13 Jun 19:53:39 - [info] 
Welcome to Node-RED
===================
13 Jun 19:53:39 - [info] Node-RED version: v2.2.2
13 Jun 19:53:39 - [info] Node.js  version: v16.15.0
13 Jun 19:53:39 - [info] Linux 5.15.41 x64 LE
13 Jun 19:53:40 - [info] Loading palette nodes
13 Jun 19:53:42 - [info] Dashboard version 3.1.7 started at /endpoint/ui
/config/node-red/node_modules/node-red-node-pi-gpio/testgpio: line 5: python: command not found
/config/node-red/node_modules/node-red-node-pi-gpio/testgpio: line 8: -u: command not found
13 Jun 19:53:42 - [warn] rpi-gpio : Raspberry Pi specific node set inactive
13 Jun 19:53:43 - [info] Settings file  : /etc/node-red/config.js
13 Jun 19:53:43 - [info] Context store  : 'default' [module=memory]
13 Jun 19:53:43 - [info] User directory : /config/node-red/
13 Jun 19:53:43 - [warn] Projects disabled : editorTheme.projects.enabled=false
13 Jun 19:53:43 - [info] Flows file     : /config/node-red/flows.json
13 Jun 19:53:43 - [info] Server now running at http://127.0.0.1:46836/
13 Jun 19:53:43 - [info] Starting flows
[19:53:44] INFO: Starting NGinx...
13 Jun 19:53:45 - [info] Started flows
13 Jun 19:53:46 - [error] [api-current-state:House Unoccupied?] Entity could not be found in cache for entity_id: binary_sensor.house_occupied
13 Jun 19:53:46 - [error] [api-current-state:House Unoccupied?] Entity could not be found in cache for entity_id: binary_sensor.house_occupied
13 Jun 19:53:48 - [info] [server:Home Assistant] Connecting to http://supervisor/core
13 Jun 19:53:48 - [info] [server:Home Assistant] Connected to http://supervisor/core
13 Jun 19:53:49 - [red] Uncaught Exception:
13 Jun 19:53:49 - [error] Error: JSONata Error: Argument 1 of function "contains" does not match function signature
    at EventsState.getComparatorResult (/config/node-red/node_modules/node-red-contrib-home-assistant-websocket/dist/nodes/BaseNode.js:241:27)
    at EventsState.onHaEventsStateChanged (/config/node-red/node_modules/node-red-contrib-home-assistant-websocket/dist/nodes/events-state/controller.js:71:32)
    at EventsState.onStatesLoaded (/config/node-red/node_modules/node-red-contrib-home-assistant-websocket/dist/nodes/events-state/controller.js:179:18)
    at EventEmitter.emit (node:events:539:35)
    at /config/node-red/node_modules/node-red-contrib-home-assistant-websocket/dist/homeAssistant/Websocket.js:223:27
[19:53:49] WARNING: Node-RED crashed, halting add-on
[19:53:49] INFO: Node-RED stoped, restarting...
s6-rc: info: service legacy-services: stopping
[19:53:49] INFO: Node-RED stoped, restarting...
s6-svwait: fatal: supervisor died
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service legacy-cont-init: stopping
[19:53:49] INFO: nginx stoped, restarting...
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped

Did you address this? 1880 is the default

The other warning looks to be an event state node that is using contains where the is ,> ,< drop down is.

1 Like

Thanks for pointing me in the right direction.

In a couple of state nodes, I was using the JSONata type in an If State. Like the following:

$contains(
   $entity().attributes.connected_paired_devices,
   "AB:CD:EF:01:02:03"
)

I disabled these nodes and now Node-RED can run without crashing. I’ll go back and fix these at a later date.

Your note about the 1800 port. I’m using the Node-RED addon which I think is using Ingress. So have never had to set a port. Doesn’t appear to be causing any issues. Thanks again for your help.

First I think you need to put it all in line

$contains( $entity().attributes.connected_paired_devices, "AB:CD:EF:01:02:03" )

and set both to fields to JSONata

image

If I recall correctly there was a breaking change with the app where they now send lists as an array, not strings.

https://github.com/home-assistant/android/pull/2478

I have both fields set to JSONata. I think it might be the latter, that the way the data is supplied as an array and not a string. I’m not very familiar with JSONata and java, more comfortable with jinja2 and YAML.

The node is waiting to see if a Bluetooth device is connected.

"A0:E9..." in $entity().attributes.connected_paired_devices

I can’t get that to fire, perhaps i am using it wrong. I also tried i instead of JSONata drop down too

I can only get it to fire with a trigger node and regex filter.

image

As Kermit suggested this works for me.

[{"id":"f22fc7f1.842458","type":"server-state-changed","z":"f506f890.db8b98","g":"a8f2d9c01191e350","name":"Bluetooth Connected","server":"79d7078a.622af8","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.mi_10_bluetooth_connection","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"\"A0:E9:DB:00:4A:CA\" in $entity().attributes.connected_paired_devices","halt_if_type":"jsonata","halt_if_compare":"jsonata","outputs":2,"output_only_on_state_change":false,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":140,"y":1180,"wires":[[],[]]},{"id":"79d7078a.622af8","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]

I dont know it does not work for me, only the trigger node. Ive tried with different macs. I put an erroneous mac just to make sure the trigger wasn’t always returning true and it doesn’t. c’est la vie :man_shrugging:

HA 2022.6.6
NR 12.0.2
WS 0.43.1

image

[{"id":"fdaa9cba938443b4","type":"server-state-changed","z":"f80b6c338afd5483","name":"","server":"6b1110b5.183a4","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.pixel_3_bluetooth_connection","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"\"FC:A8:9A:A1:A9:67\" in $entity().attributes.connected_paired_devices","halt_if_type":"jsonata","halt_if_compare":"jsonata","outputs":2,"output_only_on_state_change":false,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":490,"y":840,"wires":[["202562f667604293"],["9a7c2a72f55f959c"]]},{"id":"f22fc7f1.842458","type":"server-state-changed","z":"f80b6c338afd5483","name":"Bluetooth Connected","server":"6b1110b5.183a4","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.pixel_3_bluetooth_connection","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"\"FC:A8:9A:A1:A9:67\" in $entity().attributes.connected_paired_devices","halt_if_type":"jsonata","halt_if_compare":"jsonata","outputs":2,"output_only_on_state_change":false,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":400,"y":920,"wires":[["202562f667604293"],["9a7c2a72f55f959c"]]},{"id":"c09d04c7abf97117","type":"trigger-state","z":"f80b6c338afd5483","name":"","server":"6b1110b5.183a4","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"sensor.pixel_3_bluetooth_connection","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"property","propertyValue":"new_state.attributes.connected_paired_devices","comparatorType":"is","comparatorValueDatatype":"re","comparatorValue":"FC:A8:9A:A1:A9:67"}],"inputs":0,"outputs":2,"customoutputs":[],"outputinitially":true,"state_type":"str","enableInput":false,"x":490,"y":1020,"wires":[["92804010846f7649"],[]]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"30"}]

Can anyone offer me some advise, my node red was working until July update now it won’t open from the side bar and always gives “502 bad gateway” error.

Here is the crash log from the config page

[21:09:23] WARNING: Node-RED crashed, halting add-on
[21:09:23] INFO: Node-RED stoped, restarting...
s6-rc: info: service legacy-services: stopping
[21:09:23] INFO: Node-RED stoped, restarting...
s6-svwait: fatal: supervisor died
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped

I tried uninstalling and then reinstalled but still fatal crash…

You’d be better off starting a new post / topic with your specific question / issue. More likely to get some answers.

In the meantime, have you tried setting the safe_mode: true in the Node-Red addon config? Might help you to get Node-Red to start and then you can try an identify what node(s) are causing it to crash on start-up? It’s likely that a breaking change is causing the issue. Do you know what version number you updated from and to in July?

1 Like

Or in one of the ten other 502 error posts. The first one has detailed instructions on how to do a proper remove and reinstall.

https://community.home-assistant.io/search?q=502%20%23third-party:node-red

1 Like