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

Add a SSE reconnection mechanism #1807

Merged
merged 4 commits into from
Apr 5, 2023
Merged

Conversation

florian-h05
Copy link
Contributor

@florian-h05 florian-h05 commented Mar 27, 2023

Currently, on SSE failure there is no reliable reconnection mechanism (browsers might try something), e.g. on network failure, and therefore SSE connection is lost forever once an error occurs. To reconnect, the user has to change/reload the page.

This implements a SSE reconnection mechanism, that attempts a SSE reconnection after SSE failure.
The time is increasing from 1 -> 2 -> 4 -> 8 -> 10.

The heartbeat callback is called in the alive message listener and doesn't need to be called again inside setKeepalive method.

The intervalId is removed on clearKeepalive.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
This implements a reconnection mechanism on SSE failure that attempts a reconnection after 10 seconds.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
@florian-h05 florian-h05 requested a review from a team as a code owner March 27, 2023 19:34
@relativeci
Copy link

relativeci bot commented Mar 27, 2023

Job #896: Bundle Size — 15.67MiB (~-0.01%).

822555e(current) vs cabc9ec main#895(baseline)

⚠️ Bundle contains 16 duplicate packages

Metrics (1 change)
                 Current
Job #896
     Baseline
Job #895
Initial JS 1.72MiB(+0.01%) 1.72MiB
Initial CSS 608.59KiB 608.59KiB
Cache Invalidation 93.91% 93.91%
Chunks 219 219
Assets 689 689
Modules 1706 1706
Duplicate Modules 82 82
Duplicate Code 1.72% 1.72%
Packages 137 137
Duplicate Packages 15 15
Total size by type (2 changes)
                 Current
Job #896
     Baseline
Job #895
CSS 857.87KiB 857.87KiB
Fonts 526.1KiB 526.1KiB
HTML 1.23KiB 1.23KiB
IMG 140.74KiB 140.74KiB
JS 9.18MiB (~-0.01%) 9.18MiB
Media 295.6KiB 295.6KiB
Other 4.7MiB (~+0.01%) 4.7MiB

View job #896 reportView main branch activity

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
@florian-h05 florian-h05 added bug Something isn't working main ui Main UI labels Mar 27, 2023
@florian-h05 florian-h05 added this to the 4.0 milestone Mar 27, 2023
@ghys
Copy link
Member

ghys commented Mar 29, 2023

This is critical and very sensitive code but it also seems like with those changes it received proper care and should therefore be tested properly, so I cannot do that right now, but will do!
Thanks for the time spent on this. I especially like this:

The time is increasing from 1 -> 2 -> 4 -> 8 -> 10.

@florian-h05
Copy link
Contributor Author

I agree that this should be tested, I am already doing that in my production since Tuesday.

Works fine until now. Together with #1808 I have noticed that, if I leave Safari on my iPad and come back, the SSE connection is lost, but however thanks thanks to this PR it is restored in a matter of seconds.

The heartbeatCallback should be called when the SSE connection times out.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Copy link
Contributor

@digitaldan digitaldan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@ghys ghys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll admit I didn't do the exhaustive testing I wanted, but I don't think we should postpone it any further either since it seems quite the improvement - and the code looks good 👍

@ghys ghys merged commit 6cbc0a0 into openhab:main Apr 5, 2023
@florian-h05 florian-h05 deleted the sse-reconnection branch April 5, 2023 19:21
ghys pushed a commit that referenced this pull request Apr 6, 2023
Depends on #1807.

Currently, SSE connection and sending commands fail silently, which
makes the user think that everything is fine, but instead outdated
values are displayed and commands are not sent.

This implements user warnings for such cases, a large openHAB orange
toast "Communication failure" with the option to reload is displayed at
the bottom center:
- as long as SSE connection is broken
- when sending a command to an Item failed for 5 sec

If the Item does not exist (error code 404), "<Itemname> not found" is
displayed for 5 sec

--
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working main ui Main UI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants