codmpm / node-red-contrib-loxone

Connect the Loxone Miniserver to node-red via the Websocket API
MIT License
74 stars 24 forks source link

Node Red freezes because of failed attempts to connect to miniserver #42

Closed budulinek closed 4 years ago

budulinek commented 4 years ago

Problem: Nodes attempt to connect to Loxone even if login credentials are missing. This (obviously) leads to errors in syslog:

Jan 30 07:55:49 L403-sn50 Node-RED[5769]: 30 Jan 07:55:49 - [info] [loxone-miniserver:51a8d49f.d98894] connection closed: Socket Error: undefined ERR_STREAM$
Jan 30 07:55:49 L403-sn50 Node-RED[5769]: 30 Jan 07:55:49 - [info] [loxone-miniserver:51a8d49f.d98894] connection closed: reconnecting
Jan 30 07:55:49 L403-sn50 Node-RED[5769]: 30 Jan 07:55:49 - [info] [loxone-miniserver:f9ff3407.c04ec8] Miniserver connected (10.10.10.10:10010) using Token-$
Jan 30 07:55:49 L403-sn50 Node-RED[5769]: WebSocket error:  Socket Error: undefined ERR_STREAM_WRITE_AFTER_END 1006
Jan 30 07:55:49 L403-sn50 Node-RED[5769]: 30 Jan 07:55:49 - [error] [loxone-miniserver:f9ff3407.c04ec8] Miniserver connection error: Socket Error: undefined$
Jan 30 07:55:49 L403-sn50 Node-RED[5769]: Websocket Connection closed:  1006 Socket Error: undefined ERR_STREAM_WRITE_AFTER_END
Jan 30 07:55:49 L403-sn50 Node-RED[5769]: 30 Jan 07:55:49 - [info] [loxone-miniserver:f9ff3407.c04ec8] connection closed: Socket Error: undefined ERR_STREAM$
Jan 30 07:55:49 L403-sn50 Node-RED[5769]: 30 Jan 07:55:49 - [info] [loxone-miniserver:f9ff3407.c04ec8] connection closed: reconnecting
Jan 30 07:55:50 L403-sn50 Node-RED[5769]: 30 Jan 07:55:50 - [info] [loxone-miniserver:715b1c25.99c1dc] Miniserver connected (10.10.10.10:10010) using Token-$
Jan 30 07:55:50 L403-sn50 Node-RED[5769]: WebSocket error:  Socket Error: undefined ERR_STREAM_WRITE_AFTER_END 1006
Jan 30 07:55:50 L403-sn50 Node-RED[5769]: 30 Jan 07:55:50 - [error] [loxone-miniserver:715b1c25.99c1dc] Miniserver connection error: Socket Error: undefined$
Jan 30 07:55:50 L403-sn50 Node-RED[5769]: Websocket Connection closed:  1006 Socket Error: undefined ERR_STREAM_WRITE_AFTER_END
Jan 30 07:55:50 L403-sn50 Node-RED[5769]: 30 Jan 07:55:50 - [info] [loxone-miniserver:715b1c25.99c1dc] connection closed: Socket Error: undefined ERR_STREAM$
Jan 30 07:55:50 L403-sn50 Node-RED[5769]: 30 Jan 07:55:50 - [info] [loxone-miniserver:715b1c25.99c1dc] connection closed: reconnecting

etc etc. The attempts to reconnect are so frequent that Node Red (in my case running on Raspberry Pi 3) becomes unresponsive. And of course, loggs fill memory (SD card).

Why are login credentials missing? Credentials are never stored during export of flow. After (re)importing the flow, you always have to enter them manually. If you forgot to do so and deploy the flow without credentials, the flow starts, but Node Red becomes unresponsive, because of errors and attempts to reconnect.

Suggested solution:

codmpm commented 4 years ago

Thank you for this issue!

Delays between attempts to reconnect (for example 10 seconds?) in order to prevent Node Red becoming unresponsive.

I think this is handled by the underlying node-lox-ws-api and is not exposed, so I can't change that.

Disable connection if login credentials (in loxone-miniserver node) are missing.

I think this is the way to go... as far as I know it is not possible to connect to the miniserver without credentials anyway, or is it?

Exporting the credentials with a flow export ist not valid, as these are sensitive informations and could then be - without knowing - made public by exporting a flow. Node-red itself advises to store them separately: https://nodered.org/docs/creating-nodes/credentials

I will disable the connection when no credentials are given in a future release.

budulinek commented 4 years ago

Thanks a lot!

Yes, as far as I know, it is not possible to connect to miniserver without credentials. So it is safe to make credentials obligatory and disable connection and throw an error ("red triangle" in Node Red) if credentials are missing.

codmpm commented 4 years ago

Btw, the red triangle is provided by the node-red editor. It appears after an editor reload if the node-config is not complete.