Skip to content
This repository has been archived by the owner on Nov 8, 2021. It is now read-only.

"Realm is empty" when initiated through Android #251

Open
1 of 3 tasks
misterlib opened this issue Aug 14, 2017 · 23 comments
Open
1 of 3 tasks

"Realm is empty" when initiated through Android #251

misterlib opened this issue Aug 14, 2017 · 23 comments

Comments

@misterlib
Copy link

Our app is built in React Native, published on iOS and Android.

Everything is working as expected on iOS.

After migrating from a local realm to a synced realm and connecting to the ROS, a new user is created, but when trying to view the data in the Realm, it says "Realm is empty".

More potentially helpful information: while sync is working between devices on iOS, when connecting to that Realm from an Android device, the authentication works, but no data is actually transferred to the Android device from the server.

Goals

Connect to server and read/write to a realm on Android

Expected Results

After authentication, the data would begin flowing in both directions.

Actual Results

After authentication, nothing happens.

Steps to Reproduce

I'm not sure.

Code Sample

We could search for some code to provide, but it is working on iOS, so not sure it is something that needs to change in the code.

(Side note, we migrated to ROS2.0 last week and have rolled back and have begun encountering this issue as we have reworked the code to work on ROS1 again, which it is on iOS. This abnormality with Android was not happening before the upgrade and then subsequent downgrade)

Version of Realm and Tooling

  • Realm Object Server Version: 1.8.3
  • Flavor:
    • Developer
    • Professional
    • Enterprise
  • Server OS & Version: CentOS 7
  • Client SDK Version: Realm 1.10.0 -
  • Client OS & Version: Android (using realm-js via React Native)

Logs

systemctl status realm-object-server.service Paste output here
sudo journalctl -u realm-object-server.service Paste output here
cat /var/log/realm-object-server.log Paste output here
@bigfish24
Copy link

This might just be as simple as the Realm hasn't completely downloaded. You can figure out when the Realm is downloaded by asynchronously opening the Realm: https://realm.io/docs/java/latest/#asynchronously-opening-realms

Or you can attach a progress notification: https://realm.io/docs/java/latest/#sync-sessions

Opening a Realm normally will give you immediate access (synchronously) but the data still must be synced down that already exists for that Realm which happens asynchronously.

@morten-krogh
Copy link

@misterlib

If there is still a problem, I would aske you to turn on debug level logging on both the Android client and server.
Make sure that there is no other activity for some time, and then start the Android app.
Could you send the server and client log files for this small experiment?

Thanks.

@misterlib
Copy link
Author

We tried the async solution that @bigfish24 had mentioned and got it up and running today, but it didn't help. The issue remains. We are going to try to run the logs tonight, but we have a beta build out to testers that we can't make absolute sure that they won't try to access the server. Hopefully we can still get enough information from the logs to help diagnose the problem.

This wasn't (in my recollection) an issue before we upgraded to ROS 2 and then had to downgrade. I'm not sure which client version we were using before, but just to make sure, no one else is reporting this issue with Android connectivity issues with Realm 1.10.0 and ROS 1.8.3?

Thanks. We'll post logs later tonight.

@jasonmerino
Copy link

@morten-krogh I have collected some logs from the Android app as well as the server. As @misterlib mentioned some of the logs may be from other users that are out of our control, but things looked pretty quiet before I started to collect the logs.

The actions that I took were logging into an existing sync user and open a synced realm with that user. The login works correctly, but the data is never fetched. We are using realm-js in our React Native app. This flow works on iOS and for this portion there isn't any platform specific code, but it doesn't work on Android.

Any help you could provide would be greatly appreciated. Thanks!

client-log.txt
server-log.txt

@morten-krogh
Copy link

@jasonmerino

I don't see any sync activity in the client-log.txt at all. Is this log captured while you
sync?

The server did not receive any sync request from your client either.

Basically, nothing important happened in these log files.

Can you try again? What log level do you use on the client?

Try to sync from iOS as well such that I can see the server log with the iOS connection as well.

Thanks.

@jasonmerino
Copy link

@morten-krogh those logs were captured while I was attempting to sync. The data never comes through though. I have created new captures of the logs on both Android and iOS from the client and server. On the Android client I used the verbose log level and on iOS I used the default. Here's what happened.

android-client-log.txt
android-server-log.txt
ios-client-log.txt
ios-server-log.txt

@morten-krogh
Copy link

Yes, it seems clearly like the problem originates from the Android device.

Are you sure that your code is correct on Android. Did the same code work before?

Can you post the code?

@jasonmerino
Copy link

@morten-krogh Here is the code we call. We start off by calling the logUserIn function with the credentials and the callback.

  getRealmObjectServerURL() {
    return `https://${env.realmHost}:${env.realmPort}`;
  },

  logUserIn({ username, password }, next) {
    Realm.Sync.User.login(
      realmManager.getRealmObjectServerURL(),
      username,
      password,
      (error, user) => {
        if (error) {
          return typeof next === 'function' && next(error);
        }
        realmManager.initializeSyncedRealm(user, (error, realm) => {
          return typeof next === 'function' && next(error, user, realm);
        });
      },
    );
  },

  initializeSyncedRealm(user, next) {
    realmManager.logInToSyncedRealmWithUser(user, next);
  },

  logInToSyncedRealmWithUser(user, next) {
    Realm.openAsync(
      {
        sync: {
          user,
          url: `realms://${env.realmHost}:${env.realmPort}/~/placefordata`,
        },
        schema: realmManager.getSchema(), //return schema
      },
      (error, realm) => {
        realms.synced = realm;
        if (typeof next === 'function') {
          next(error, realm);
        }
      },
    );
  },

Do you see anything wrong with this code? I assume not, because this code is working on iOS. But if you see any issues I would be happy to update things to see if we could get this fixed.

Thanks!

@bigfish24
Copy link

@jasonmerino can you turn on debug logs for Realm: https://realm.io/docs/java/latest/#logging

This will help reveal what is wrong with the client.

@jasonmerino
Copy link

@bigfish24 it looks like there is no RealmLog class for the react native library. I've got the following import in the apps MainApplication.java

import io.realm.react.RealmReactPackage;

But I tried pasting that code in there and it says that it cannot resolve RealmLog. Do I need to install the standard realm java library in addition to get this logging or is there a way to do it with the RealmReactPackage?

I also attempted to set the sync logging level on the JS side but it looks like Realm.Sync.setLogLevel is undefined in [email protected]...

@bigfish24
Copy link

For JS it should be Realm.Sync.setLogLevel('debug') did you not import Realm?

@jasonmerino
Copy link

@bigfish24 I just tried to get the logs again. I guess I was doing something wrong before because it didn't crash this time, but when I tried to get the logs again they look pretty similar as they did before. Here's the log.

android-sync-debug-log.txt

Just for the heck of it I had @misterlib set up a non encrypted realm and pointed the existing code to that one and I was able to log in just fine. So it seems there is some issue with the encrypted realm connection, but the logs don't seem to reflect any issues. I'm a little stumped.

@misterlib
Copy link
Author

@morten-krogh
Copy link

Let us check if there is a problem with the client rejecting the server's SSL certificate.

Try to set validate_ssl: false in the sync object

sync: {
user,
url: realms://${env.realmHost}:${env.realmPort}/~/placefordata,
validate_ssl: false
}

@jasonmerino
Copy link

@morten-krogh setting valiate_ssl to false worked. The data comes through as expected when I log in and open the synced realm on both Android and iOS.

Now, how do we find out if it's an issue with our cert, the Android SDK, or the iOS SDK?

@morten-krogh
Copy link

@jasonmerino Good to hear.

We actually know about similar issues.

It is not an issue with your own certificate.

It is an issue in our system that has to do with the way our JS SDK is combined with openssl, I believe.
We have seen similar issue in our node.js binding.

I suggest that you set validate_ssl to false until we solve the issue.

You are still using a SSL connection when validate_ssl = false.
The certificate is just not being verified by the client.
There is a theoretical risk that a man in the middle inserts a fake certificate. I think you can ignore this risk for the moment. It is still a SSL connection, as I said.

We will hopefully soon get to the bottom of this issue.

@jasonmerino
Copy link

jasonmerino commented Aug 18, 2017

@morten-krogh do you have an issue on Github that I can subscribe to where you guys are tracking progress on this?

@morten-krogh
Copy link

@jasonmerino I don't know if there is a public issue. We will keep this issue open.

@jasonmerino
Copy link

@morten-krogh that works for me. Thanks!

@Damnum
Copy link

Damnum commented Sep 3, 2017

I have the same problem on React Native, realm-js library. It works on iOS. On Android, Realm.open hangs and never returns. I don't see anything special in the logs, even when setting Realm.Sync.setLogLevel('debug'). User is correctly logged in.

My synced realm is read-only and not encrypted. Setting validate_ssl = false does not help either.

I'm using no special code for iOS vs. Android, yet it only works in iOS. This happens on emulator and device, both on localhost and webserver.

@Damnum
Copy link

Damnum commented Sep 7, 2017

@morten-krogh could you have look at my logs? On the client site, the Android log is silent: The call wait_for_download_completion just hangs and never returns.

server-log-ios-WORKING.txt
server-log-android.txt

@morten-krogh
Copy link

@Damnum I will look at it soon.

@morten-krogh
Copy link

@Damnum

Yes, the log for the Android client shows that the server receives nothing from the Android
client.

We will look into this.

@kneth kneth removed their assignment Sep 6, 2018
@morten-krogh morten-krogh removed their assignment Mar 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants