-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Discussion: What should be the correct behavior on hibernating browser tabs? #6810
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
Comments
This issue is especially affects mobile devices. I think need the mechanism to switch leader tab to latest active tab, since the latest active tab will have most longer lifecycle until its suspended and after user get backs to website, the new opened tab becomes leader again and this will make it not noticeable for end user and fix the issue. |
@andreuka But on mobile, if a tab is hibernated, doesnt it also elect a new tab as leader? Because in my testings it does. |
I mostly testing at iOS and from my experience its not hibernating its immediately, its firstly put it in kind of slow mode and I had alot of complains from users that the application does not works well at mobile devices. I do not using replication, but I had noticed that by my custom WebSocket connection which opened in both tabs and pushs same events to all tabs, but if only leader tab writes data to database and when tabs are switched, the leader was not changed, so I made a hack, that on mobile every tab with active WebSocket connection writing the data to the database and that works enough well, since only 1 tab will work fast. That is my function to determine if tab should write data to database or not:
but thats not perfect solution as you can see and I hope that can be done other way. |
The "hack" is already there. I can think of two options.
...or
|
Hello everyone. Just released version I also added some tests to ensure that the replication works without problems when running from two tabs at the same time. Please test this, when it works for everyone, I will remove the previous click-event-hack and also make |
Closing this. On the next major version, |
@pubkey Hello, thank you for adding Here is a list of devices we tested:
For the last few weeks, we’ve had a hard time with our The first thing we discovered is that all devices using eMMC storage types are facing this issue. eMMC is known for having low random write speeds, which are crucial for SQLite. All phones that used UFS were not affected. After a long debugging session, we figured out that |
@space7panda It think it is very unlikely that this comes from Maybe you have a custom conflict handler which causes infinite write loops? |
Thanks, we can double check that but im not sure how conflict Handler is related to our testing where we had 2 separate apk files where: And also as additional testing we downgraded our RxDb to 15.39.0 and everything worked fine there because toggleOnDocumentVisible hasn't been implemented yet |
You could use the logger plugin to check what is going on in your storage. Likeky some other writes block your bulk-inserts so they are slow waiting to open a transaction. |
Sure we will check that and elaborate on results |
@pubkey I can confirm that At first I was thinking this issue is related to something else, but after a very long debugging session I concluded it must be the In our case the app is stuck in a never ending loading cycle and will stay stuck until safari is closed (or all tabs of the app are closed) My suspicion is that this is related to the // important is that none of the functions are actually awaited even though they are async
replicationState.start();
replicationState.pause();
replicationState.start(); |
@pubkey as a followup I've debugged the whole thing with the logger plugin and those are the operations which aren't finishing:
My bug is also NOT happening with the The dexie storage gives some errors which the
I'm happy to give further data / assist you in fixing this issue. |
I do not see any reason why a call to Since this is reproducible with the dexie storage, it should be possible to make a PR with a test case? |
I couldn't reproduce the hanging behavior in safair with The PR #7095 fixed the hanging issue for us, but we still think that if one does |
No a try-catch is not the correct solution. We should detect where this comes from. |
@pubkey its thrown here: rxdb/src/plugins/replication/index.ts Line 421 in df21fdc
this.internalReplicationState is undefined)
So maybe before |
If .pause is called while .start is still starting up, the .pause call should await the startup-procedure. This likely would also fix your |
@pubkey well, before I guess its a good idea to implement that, although I don't have the capacity to make PR for now |
@KingSora @pubkey our issue also related to We are using Capacitor with RxDb and
Basically users can hide and open app 10 times in a row which will cause 10X combo of |
then we tried to simulate that with following pseudo code: App.addListener('appStateChange', ({ isActive }) => {
....
replicationState.start();
....
replicationState.pause();
....
}); And we got same results with a bit less lag |
@space7panda I could not reproduce your problem. Can you make a PR with a test case that simulates this behvior and shows that it causes errors? |
Uh oh!
There was an error while loading. Please reload this page.
Context
Browser can "hibernate" browser tabs when they are not active. This ensures these tabs do not use any memory or CPU, the JavaScript process on these hibernated tabs is then stopped.
RxDB uses a leader-election for replication so that when many tabs are open, only one tab runs the replication. This saves a lot CPU power and bandwith.
People often reported that they had problems when the elected leader-tab became hibernated by the browser. This seemingly stopped the replication and caused problems.
To prevent this, RxDB added a hack to prevent tab hibernation if at least one replication is running: c2c7ea4
But this hack is not good as it stops the device from power saving when the tab is not in use.
Goal
I will remove this hack in the next release. From my testings, the default behavior of RxDB with hibernating tabs is correct: The hibernated tab dies and a new leader is elected. You can test this behavior with the broadcast channel test-page where the leading tab has a crown-icon in the title. You can manually send tabs to hibernation in chrome at
chrome://discards/
.Question
Do you have any way to reproduce a case where the default behavior causes problem?
What do you think the default behavior of RxDB should be?
Related discussions:
The text was updated successfully, but these errors were encountered: