mauricedominic / node-red-contrib-huemagic

Philips Hue node to control bridges, lights, groups, motion sensors, temperature sensors and Lux sensors using Node-RED.
https://flows.nodered.org/node/node-red-contrib-huemagic-fork
Apache License 2.0
19 stars 3 forks source link

[Bug]: Detection missing for lost connection to HUE Bridge #4

Open cogweg opened 1 year ago

cogweg commented 1 year ago

Node-Red-Contrib-Huemagic-Fork Version

4.2.6

Node JS Version

16.19.0

NPM Version

8.19.3

Node-Red Version

3.0.2

Operating System

Ubuntu 22 LTS on Raspberry Pi4

What happened?

Hue bridge SSE subscription gets lost. Huemagic bridge nodes do not get updates after some time (around some hours) after restarting node-red or the flow.

A secondary issue is, that there are frequent https session established from hue-magic to the hue bridge. This looks to be rather obsolete and does not help to repair lost SSE subscriptions.

I believe, there is a missing TCP keepalive. Looking at to traces there are tcp keepalive packets only from the hue bridge towards node-red. The hue bridge sends the keepalive packets every 20 sec. But the hue bridge stopps sending the keepalive tcp packets for whatever reaseon. The node does not detect the connection issue, no reconnect (new SSE subsribption), and therefor cannot get further updates from hue switches, lights etc.

The TCP connection seems to stay in Established state forever even when the keepalive packets from the hue bridge are no longer received. I use "ss -et" which shows the established socket. But "tcpdump" shows no packets anymore.

How to reproduce?

  1. Start node-red with hue-bridge
  2. check SSE events are working, do nothing
  3. hue bridge is subscribed and sending tcp keepalive
  4. ... and some time, keepalive are stopped, most likely the hue bridge stopps the socket
  5. huemagic is not working anymore and does not detect the failure

Expected behavior:

Huemagic shall re-subscripe to the hue bridge.

For that, it should use tcp keepalive.

Additional comments?

Using curl for SSE subscription, it can detect the hue bridge failure. curl process is sending tcp keppalives itself. The command I use is: curl --insecure -N -H 'hue-application-key: {{ my key is here }}' -H 'Accept: text/event-stream' https://192.168.178.73/eventstream/clip/v2

Relevant log output

No response