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

Recover from broken websocket connection #403

Closed
wants to merge 5 commits into from
Closed

Recover from broken websocket connection #403

wants to merge 5 commits into from

Conversation

leonardmgh
Copy link

As described here: home-assistant/frontend#17409 the HA frontend sometimes ends up with a broken web-socket connection to the backend. No error disconnect even/error is ever thrown. To work around this i have implemented a polling mechanism from the backend to the frontend.
The frontend sends a ping message to the backend after it hasn't received any messages for 60 seconds with a 5 second timeout and forces the socket to close if no response is recieved.

@home-assistant
Copy link

Hi @LeHaTrifork

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

1 similar comment
@home-assistant
Copy link

Hi @LeHaTrifork

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant
Copy link

Hi @leonardmgh

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@balloob
Copy link
Member

balloob commented Aug 2, 2023

I don't think that this belongs in HAWS. This can be added to the frontend if it's necessary. The frontend already has a lot of mechanisms for this, and if those don't fully work, they need to be fixed.

It's also very inefficient to clear the timer on every message. We receive a lot of messages. That's creating/clearing a lot of timers. Better to check from time to time if it's still connected.

@balloob balloob closed this Aug 2, 2023
@leonardmgh
Copy link
Author

I don't think that this belongs in HAWS. This can be added to the frontend if it's necessary. The frontend already has a lot of mechanisms for this, and if those don't fully work, they need to be fixed.

It's also very inefficient to clear the timer on every message. We receive a lot of messages. That's creating/clearing a lot of timers. Better to check from time to time if it's still connected.

Fair enough, i was also a bit split on where to implement this mechanism. Currently (20230705.1) the mechanisms in the frontend don't work for my scenario. In general i think it's needed to implement a pinging mechanism to the backend, since the reported state of the websocket by the browser can be unreliable and this would catch 100% of the scenarios.

Regarding my implementation, i can see that the clearing of timers is inefficient. My intention was to only ping the backend when it's really necessary to avoid messing with the connection and causing unwanted behaviour when the connection actually is active. But i think i just overcomplicated things here.

@leonardmgh
Copy link
Author

Also, where would in your opinion be the best place to implement this functionality in the frontend? @balloob

@onionmad
Copy link

@balloob Why was this issue closed? I feel we need a solution to this, as it would solve this issue, along with a bunch of others, right?
home-assistant/iOS#2379

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

Successfully merging this pull request may close these issues.

3 participants