Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WS connections hangs #488

Closed
1 task done
bkupidura opened this issue Oct 17, 2021 · 0 comments
Closed
1 task done

WS connections hangs #488

bkupidura opened this issue Oct 17, 2021 · 0 comments

Comments

@bkupidura
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Im running Home-Assistant and Node-Red on top of K8s. Node-Red is connecting to HA over K8s service.
When i forcefully kill node on which HA is running, websocket connection hangs in some weird state.

Its not receiving new events, and unable to publish anything. After some time NR detects connection failure and establish new one.

In below log i killed HA node arround 10:14, new HA instance was spawned ~10:17 - but NR->HA WS connection was restored 10:30.

17 Oct 10:10:25 - [info] [server:Home Assistant] Connected to http://home-assistant.smart-home:8123
17 Oct 10:16:31 - [error] [api-render-template:Get unavailable sensor] Error get-template: connect ETIMEDOUT 10.43.183.41:8123
17 Oct 10:17:30 - [error] [api-render-template:Get unavailable sensor] Error get-template: connect ETIMEDOUT 10.43.183.41:8123
17 Oct 10:18:30 - [error] [api-render-template:Get unavailable sensor] Error get-template: connect ETIMEDOUT 10.43.183.41:8123
[...]
17 Oct 10:30:02 - [info] [server:Home Assistant] Connection closed to http://home-assistant.smart-home:8123
17 Oct 10:30:02 - [info] [server:Home Assistant] Connecting to http://home-assistant.smart-home:8123
17 Oct 10:30:02 - [info] [server:Home Assistant] Connected to http://home-assistant.smart-home:8123

Connection to HA is terminated on K8s service (this is why it didnt noticed HA failure).

To better/faster detect WS failures can we add keepalive to node-red-contrib-home-assistant-websocket?

I see that home-assistant-js-websocket is already exposing ping method - https://github.com/home-assistant/home-assistant-js-websocket/blob/fdbeeee943e7f89f80db84ce2a42a41db9120be3/lib/connection.ts#L221

If we can just sent ping every N seconds, and after X failures forcly close connection - we should be able to recover much faster from this kind of issue.

I would love to help with implementation, but JS/TS is little black magic for me :) If i can help in testing or anything just ping me and i will be happy to do so.

To Reproduce

On my environment:

  1. Run HA+NR on K8s
  2. Connect NR to HA WS over K8s service
  3. Kill node on which HA is running
  4. Spawn new HA POD

Probably same can be tested without K8s, just using simple LB between NR and HA but im not sure.

Expected behavior

NR able to detect WS failure much faster.

Screenshots

No response

Example Flow

No response

This package's version

0.34.0

Is Node-RED running in Docker?

Yes

Node-RED version

2.0.6-12

Node.js version

v12.22.6

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant