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

React Native app freezes on Android devices after some time of inactivity #3984

Closed
mednche opened this issue Sep 27, 2021 · 4 comments
Closed
Labels
More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. O-Community T-Bug

Comments

@mednche
Copy link

mednche commented Sep 27, 2021

How frequently does the bug occur?

All the time

Description

Opening the app on an Android device after some time of inactivity should not freeze. Instead users should be able to return to where they left off.

Stacktrace & log output

No response

Can you reproduce the bug?

Yes, always

Reproduction Steps

We have a React Native application using Realm Sync to sync three realms (user, company and site). When running on real Android devices, if the app is left inactive for a certain amount of time, the app freezes on their latest screen (I can scroll up and down but cannot press any buttons). This issue can be replicated in Android simulators by double pressing the R key in Metro.

On real devices, closing the app and reopening does not fix the issue. The only 'fix' I’ve found is to go in App Settings and clear app data. This logs the user out and they have to log back in before using the app again (and all unsynced progress is lost).

The thing that is strange is that the data from all three realms is read correctly before the freeze happens, so it’s not like the Realm.open() is hanging (the .then() part of the code is read fine so I imagine the promise has been fulfilled?).

The issue does not occur on iOS devices. I’ve read on #3668 that Android handles cache clearing in a different way from iOS and that it could be the cause behind the problem.

This is how I open my three realms (example of user realm here):

`

const OpenRealmBehaviorConfiguration = {
    type: 'openImmediately',
  };
const config = {
  schema: [User.schema],
  sync: {
    user: user,
    partitionValue: `user=${user.id}`,
    newRealmFileBehavior: OpenRealmBehaviorConfiguration,
    existingRealmFileBehavior: OpenRealmBehaviorConfiguration,

  },
};```

let realm = await Realm.open(config).then((userRealm) => {


realmRef.current = userRealm;


const users = userRealm.objects("user");


// Do stuff with users here
}


`

### Version
Realm 10.1.2

### What SDK flavour are you using?
MongoDB Realm (i.e. Sync, auth, functions)

### Are you using encryption?
No, not using encryption

### Platform OS and version(s)
Android: 8.1.0, 10

### Build environment
Which debugger for React Native: NA

@kneth
Copy link
Contributor

kneth commented Sep 29, 2021

The fix for #3668 was released in version 10.4.2, and I suggest that you upgrade from version 10.1.2 to latest version.

However, I am curious to know long time time "some time of inactivity" is?

@sync-by-unito sync-by-unito bot added the More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. label Sep 29, 2021
@mednche
Copy link
Author

mednche commented Sep 30, 2021

Thanks @kneth, the issue on Android was occurring randomly. I'd say after about 30 mins of inactivity or so? Sometimes it would be fine, sometimes it would freeze and I'd have to do the Clear App Data hack (which means losing all unsynced data).

Following your advice, I've upgraded to Realm 10.8.0 but I'm now getting a sync error Premature End of Input on both Android and iOS (without having changed any of my code). On iOS it occurs as soon as the phone screen is turned off for more than a minute or so. On Android, it may be a bit longer (maybe 5 mins?).

I guess it's a different issue from that initially raised here but because of this constant crashing, I can't tell whether my initial freezing issue is resolved or not. In Metro, double pressing the R key still leads to freezing so my guess is that it is not resolved yet?

Regarding this new Premature End of Input, I can't find any help anywhere about its meaning. It seems a bit vague. Any idea what could be behind this?

@no-response no-response bot removed the More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. label Sep 30, 2021
@kneth
Copy link
Contributor

kneth commented Nov 1, 2021

30 minutes sound like the access token hasn't been refreshed correctly. It might help to call Realm.App.Sync.reconnect().

Premature end of input is an error message bubbling up from the sync client when the sync client receives incorrect data. My best guess is that the connection has been broken somehow. Your app might been hibernated/put to sleep, and at least on iOS data will be encrypted. It might be a race condition where the sync client is accessing the file system before iOS has decrypted in (see also #3112).

@fronck fronck added the More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. label Nov 24, 2021
@no-response
Copy link

no-response bot commented Dec 8, 2021

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

@no-response no-response bot closed this as completed Dec 8, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
More-information-needed More information is needed to progress. The issue will close automatically in 2 weeks. O-Community T-Bug
Projects
None yet
Development

No branches or pull requests

3 participants