-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Realm SyncManager takes up to 4-5 minutes to reconnect to ROS after waking device. #7003
Comments
WifiLock and WakeLock does not fix the problem. |
I think the issue lies in the SyncSession object in the getAccessToken() method and/or otherwise how the realm-java checks for network connectivity. When looking at the following line: and looking at the NetworkStateReceiver.isOnline() method:
The above method does not adequately check if the application has access to the "available" network. When battery optimisation and doze mode kicks in, the applications access to the network is restricted and limited. While the application may still have access to the cpu and being able to run code I believe the above code allows realm java to make illegitimate network requests that will always fail and thus causing an exponential backoff policy to kick in. In other words I believe the isOnline method is only checking if the device is online but does not check if the application has access to the available network. I believe that realm-java should also, in the isOnline method, check via the PowerManager if the application is in PowerSaveMode like so:
and so I recommend to update the above method like so:
Unfortunately isPowerSaveMode is only accessible from api level 21+ and so that would need to be taken into effect. Having tricked devices into powersaving mode and disabling charging via adb while connected to android studio, I did observe via logcat that realm java makes network requests that will always fail resolving the address of ros which is very indicative of network access having been restricted to the application. After having read the realm java code I do believe the mindset has been to make sure that the library only makes network requests that are legitimate and that the code after the above check is not making any further considerations as to the network connectivity there after. Therefore I do believe there to be many cascading issues that arise as a side effect because of the current implementation of isOnline() |
Hi @helgijons First: The That said, after going over the code. I think your explanation is mostly correct. The problem does happen inside The problem is that calling This is very much a bug on our end we need to fix. Optimizing |
Hi thanks for getting back. I can confirm that SyncManager.refreshConnections() does not have any effect even when triggered multiple times. Good to know that you understand the issue. I think this is causing many bad situations where data shared between devices becomes very inconsistent if data is changed in disconnected clients. Do you envision a fix to 5.x and 6.x or only 10.x? What timeline are we looking at? I need to know because we are micro managing users, instructing them to make sure devices do not go to sleep during peek hours. |
This code path doesn't exist in 10.x, but that isn't out of BETA either. Generally, we only patch the latest release, so in this case, it would be in a 7.0.2 release. I do realize that this crosses a major version boundary, so might be problematic. I'll discuss internally and see if it would make sense to do a patch for 6.1.0 as well. |
@cmelchior - Have you determined if this fix can also be applied to the latest 6.x release? |
This has been fixed in 7.0.2. We will also release 6.1.1 shortly with the same fix. |
Thank you for fixing this issue. Just saw this version is not referenced on https://realm.io/docs/java/latest/. Is it safe to use in production? |
Yes, it should be fine 👍 |
Roger, we just pushed out an update which only upgrades the realm version. Will report back in a week. |
Goal
Keep realm fully synchronized at all times.
Actual Results
SyncManager does not automatically reconnect/refresh access tokens after raising device from sleep until 4 minutes have elapsed.
SyncManager refresh connections has no effect, does not immediately reconnect to ros, is affected by same delay.
SyncManager.stop() & SyncManager.start() has no effect. Even when called in onStart & onStop respectively.
Logging sync user out and back in resolves the issue immediately.
Steps & Code to Reproduce
Before you start:
Close realm in onDestroy
Disconnect device from power charging.
Login user
Open realm asynchronously.
Put device to sleep via power button with app in foreground.
Wait 4-5 minutes.
Wake device from sleep.
Realm will not reconnect to ros until 4-5 minutes later. Which means that any actions user makes within that time window are not synchronised to other devices via ros.
Version of Realm and tooling
Realm version(s): ?
6.0.2
Realm Sync feature enabled: Yes
Android Studio version: 4.0
Android Build Tools version: 28.0.3
Gradle version: ?
Which Android version and device(s): api level 19+ and not manufacturer specific.
The text was updated successfully, but these errors were encountered: