realm-java icon indicating copy to clipboard operation
realm-java copied to clipboard

Realm does not synchronize data with ROS - WAITING_FOR_ACCESS_TOKEN problem

Open CraneSenior opened this issue 9 years ago • 6 comments

Goal

I want realm to automatically start synchronization of data with ROS after restore the internet connection while i am still in my app <- without the need to restart application.

Actual Results

When I start my application without internet connection, and I turn it on while I'm using my app, my data will not synchronize, i see in log only:

12-02 23:52:43.147 30731-30731 D/REALM_JAVA: NetworkListener: Connection available
12-02 23:52:43.147 30731-30731 D/REALM_JNI: Callback to Java requesting token for path
12-02 23:52:43.427 30731-30731 D/REALM_JAVA: NetworkListener: Connection available
12-02 23:52:43.427 30731-30731 D/REALM_JNI: Callback to Java requesting token for path

and realm is not syncing. I tried to log more and noticed that session state even with restored internet connection is 'WAITING_FOR_ACCESS_TOKEN'

When start my app with working internet connection and lost it during using app and restore it again I see this instead:

12-02 23:52:24.667 30731-30731 D/REALM_JNI: Callback to Java requesting token for path
12-02 23:52:24.687 30731-30843 D/REALM_JNI: SyncClient thread created

and realm is start syncing. I checked a lot: path to realm, user, and correctness of few more things, I am sitting with this problem about 2 days, and I cannot solve it.

Flow description

I am authenticate user using Google, then retrieve token and using it to create realm credentials. I am login user async and then store retrieved user using UserStore. From now i am always retrieve the same user from UserStore whenever app starts. During first start of app i am creating path to realm using "/~/realm_name" and every other next time using "/user.getIdentity()/realm_name". I am retrieve realm instance in Activity OnCreate method and close in OnDestroy.

In my app I made sync transactions(using execute transaction method), I tried with async too, the same situation.

On server I have length of time (in seconds) in which access tokens are valid to 600 and the length of time (in seconds) in which refresh tokens are valid to 3153600000 - as You can see default settings.

But i think that does not matter because the problem occur only when i start my app without internet connection.

Some code below.

Code Sample

I made a standard code that i saw in internet or in docs. for example: login user:

    public void loginRealmUser() {
        SyncUser.loginAsync(SyncCredentials.google(googleAcct.getIdToken())
                , realmAccountManager.getServerAuthUrl()
                , this);
    }
 public String getServerAuthUrl() {
        return "http://" + RealmConstants.REALM_SERVER_ENDPOINT + "/auth";
    }

getting syncConfig:

    private SyncConfiguration getConfig(SyncUser user, String realmUrl){
        return new SyncConfiguration.Builder(user, realmUrl)
                .waitForInitialRemoteData()
                .build();
    }

Version of Realm and tooling

Realm version(s): JAVA -4.2.0, Realm Object Server : 2.0.17 <- Developer Edition

Realm sync feature enabled: yes

Android Studio version: 2.3.3

Which Android version and device: KitKat 4.4.4 Xperia Z1

Additionaly

I do not know what to say more or which part of code i should show, I tried to follow that what i read on realm docs and realm forum. I just want to make a possibility to work offline in app, for users it will be a mandatory requirement.

If You need more additionaly info just tell, i will try to answer questions as soon as possible.

Thanks in advance Regards

CraneSenior avatar Dec 02 '17 23:12 CraneSenior

Can you get a full log for us? from offline ~ online for a few minutes. Call RealmLog.setLevel(LogLevel.ALL) after Realm.init() to enable all logs. If it is possible, please get a server side log as well.

if you want to share it privately, you can send the log to [email protected] .

Thanks

beeender avatar Dec 05 '17 07:12 beeender

Internal note Helpscount link with log files https://secure.helpscout.net/conversation/483216935/12138?folderId=1439539

nhachicha avatar Dec 14 '17 13:12 nhachicha

Hi @CraneSenior do you still have this issue with 4.3.2 & latest ROS?

nhachicha avatar Jan 19 '18 08:01 nhachicha

@nhachicha @CraneSenior Hi. I can confirm the issue. My ROS version is 2.0.23. Yesterday I bumped up realm plugin version to 4.3.2. Before this update I had problem with sync of realm in general. Any lack of connection caused problem with sync. Only hard restart of the app was the solution. After update situation is better, but not perfect :) My not working scenario is:

  1. Install app, SyncCredentials.usernamePassword, SyncUser.login, Realm.getInstanceAsync and full sync
  2. close realm (but no user.logout), close the app, and just for sure kill the app
  3. turn off Internet connection
  4. Modify something in Realm Studio
  5. open app
  6. get SyncUser.currentUser(), create SyncConfiguration and finally Realm.getInstanceAsync
  7. I can see old cached content, but the problem is with sync (I need to kill app to reestablish connection/session )

I also have only WAITING_FOR_ACCESS_TOKEN as SyncSession status.

End of my logs:

01-19 13:11:55.740 D/REALM_JAVA: NetworkListener: Connection lost 01-19 13:14:05.591 D/REALM_JAVA: NetworkListener: Connection available 01-19 13:14:05.593 D/REALM_JNI: Callback to Java requesting token for path

If I could help with additional information, please tell me.

Regards

wtopolski avatar Jan 19 '18 12:01 wtopolski

@nhachicha UPDATE: I have just updated my ROS to 2.6.2, but the problem still occurs.

Below I put more logs: 01-19 14:01:04.737 D/REALM_JAVA: Scheduling an access_token refresh in 349263 milliseconds 01-19 14:01:04.739 D/REALM_SYNC: Connection[2]: WebSocket::Websocket() 01-19 14:01:04.739 D/REALM_SYNC: Connection[2]: Reconnecting in 0 milliseconds 01-19 14:01:04.739 D/REALM_SYNC: Connection[2]: Session[2]: Binding '/data/data/pl.wtopolski.android.warsawbikepath/files/realm-object-server/453f8d83a96ef9d6a32a4b38a657c7bb/storage/storage' to '/storage' 01-19 14:01:04.739 D/REALM_SYNC: Opening Realm file: /data/data/pl.wtopolski.android.warsawbikepath/files/realm-object-server/453f8d83a96ef9d6a32a4b38a657c7bb/storage/storage 01-19 14:01:04.741 D/REALM_SYNC: Connection[2]: Session[2]: Activated 01-19 14:01:04.742 D/REALM_SYNC: Using already open Realm file: /data/data/pl.wtopolski.android.warsawbikepath/files/realm-object-server/453f8d83a96ef9d6a32a4b38a657c7bb/storage/storage 01-19 14:01:04.742 D/REALM_SYNC: Connection[2]: Session[2]: Progress handler called, downloaded = 8394, downloadable = 8394, uploaded = 0, uploadable = 0, progress version = 0, snapshot version = 3 01-19 14:01:04.742 D/REALM_SYNC: Connection[2]: Resolving '46.101.156.210:9080' 01-19 14:01:04.743 D/REALM_SYNC: Connection[2]: Connecting to endpoint '46.101.156.210:9080' (1/1) 01-19 14:01:04.868 I/REALM_SYNC: Connection[2]: Connected to endpoint '46.101.156.210:9080' (from '10.171.45.40:34567') 01-19 14:01:04.868 D/REALM_SYNC: Connection[2]: WebSocket::initiate_client_handshake() 01-19 14:01:05.152 D/REALM_SYNC: Connection[2]: WebSocket::handle_http_response_received() 01-19 14:01:05.152 D/REALM_SYNC: Connection[2]: Will emit a ping in 600000 milliseconds 01-19 14:01:05.154 D/REALM_SYNC: Connection[2]: Session[2]: Sending: BIND(path='/storage', signed_user_token_size=609, need_file_ident_pair=0) 01-19 14:01:05.156 D/REALM_SYNC: Connection[2]: Session[2]: Sending: IDENT(server_file_ident=1, client_file_ident=45, client_file_ident_salt=8741800905379654513, scan_server_version=83, scan_client_version=0, latest_server_version=83, latest_server_session_ident=3205768050660167670) 01-19 14:01:05.157 D/REALM_SYNC: Using already open Realm file: /data/data/pl.wtopolski.android.warsawbikepath/files/realm-object-server/453f8d83a96ef9d6a32a4b38a657c7bb/storage/storage 01-19 14:01:07.706 D/REALM_SYNC: Download message compression: is_body_compressed = 0, compressed_body_size=0, uncompressed_body_size=0 01-19 14:01:07.706 D/REALM_SYNC: Connection[2]: Session[2]: Received: DOWNLOAD(scan_server_version=83, scan_client_version=0, latest_server_version=83, latest_server_session_ident=3205768050660167670, latest_client_version=0, downloadable_bytes=8394, num_changesets=0) 01-19 14:01:07.706 D/REALM_SYNC: Using already open Realm file: /data/data/pl.wtopolski.android.warsawbikepath/files/realm-object-server/453f8d83a96ef9d6a32a4b38a657c7bb/storage/storage 01-19 14:01:07.711 D/REALM_SYNC: Using already open Realm file: /data/data/pl.wtopolski.android.warsawbikepath/files/realm-object-server/453f8d83a96ef9d6a32a4b38a657c7bb/storage/storage 01-19 14:01:07.711 D/REALM_SYNC: Connection[2]: Session[2]: Progress handler called, downloaded = 8394, downloadable = 8394, uploaded = 0, uploadable = 0, progress version = 1, snapshot version = 4 01-19 14:01:25.527 D/REALM_SYNC: Connection[2]: Session[2]: Initiating deactivation 01-19 14:01:25.527 D/REALM_SYNC: Connection[2]: Session[2]: Sending: UNBIND 01-19 14:01:25.527 I/REALM_SYNC: Closing Realm file: /data/data/pl.wtopolski.android.warsawbikepath/files/realm-object-server/453f8d83a96ef9d6a32a4b38a657c7bb/storage/storage 01-19 14:01:25.528 D/REALM_JAVA: last session dropped, remove network listener 01-19 14:02:57.831 D/REALM_JAVA: first session created add network listener 01-19 14:02:57.838 D/REALM_JNI: SyncClient thread created 01-19 14:02:57.838 D/REALM_JNI: Callback to Java requesting token for path 01-19 14:02:58.485 D/REALM_JAVA: NetworkListener: Connection lost 01-19 14:03:10.414 D/REALM_JAVA: NetworkListener: Connection available 01-19 14:03:10.418 D/REALM_JNI: Callback to Java requesting token for path

wtopolski avatar Jan 19 '18 13:01 wtopolski

should be fixed in 4.3.4

nhachicha avatar Feb 06 '18 16:02 nhachicha