Search code examples
androidrealmrealm-object-server

Realm sync not working after reconnecting to the internet


I have a trouble on sync with realm object server when user connects to the object server (login), than switch Internet Off, adds new items to db, and than switch Internet ON - data not synced.
Android app uses 4.3.1 realm build

//sync
SyncUser.loginAsync(syncCredentials, urlRealm, new SyncUser.Callback<SyncUser>() {  
@Override
public void onSuccess(SyncUser user){
      syncAccount = new SyncConfiguration
           .Builder(user, urlAccount)
           .waitForInitialRemoteData()
           .name("account_"+userId+".realm")
           .modules(new AccountSchemaModules())
           .errorHandler((session, error) -> {
               Log.e("REALM", "error = " + error.getMessage());})
           .build();

                  syncAccount.shouldDeleteRealmOnLogout();

                  Realm.getInstanceAsync(syncAccount, new Realm.Callback() {
                      @Override
                      public void onSuccess(Realm realm) {
                          syncUserSuccess();
                      }
                  });
              }
          }

//then access to configuration 
Realm.getInstance(syncAccount);

I've tried to run sync when Internet comes back by calling:

syncAccount.getUser().allSessions().get(i).uploadAllLocalChanges();

but it also not helped

update

i have 3 SyncConfiguration that uses the same credential for SyncUser.loginAsync connection. can it be the reason? also i've tried to use the same SyncUser for configurations but the result was the same

is it possible to log out/log in connections manually? or what is the correct way to do that? i've tried:

syncAccount.getUser().logout()

but than on SyncConfiguration i got an error: "Configurations cannot be different if used to open the same file."

update 2 when i switch internet off i see in log:

E/REALM_SYNC: Connection[2]: Failed to resolve 'url:9080': Host not found (authoritative)
E/REALM_JAVA: java.lang.IllegalArgumentException: Unknown error code: 3
                                                           at io.realm.ErrorCode.fromInt(ErrorCode.java:195)
                                                           at io.realm.SyncSession.notifySessionError(SyncSession.java:170)
                                                           at io.realm.SyncManager.notifyErrorHandler(SyncManager.java:324)
D/REALM_SYNC: Connection[2]: Reconnecting in 795 milliseconds

but i didn't see any reconnection in log after that message

when i try to add item to db i see in log items like:

V/REALM_JNI:  --> Java_io_realm_internal_OsSharedRealm_nativeIsClosed -979144320
V/REALM_JNI:  --> Java_io_realm_internal_OsSharedRealm_nativeBeginTransaction -979144320
V/REALM_JNI:  --> Java_io_realm_internal_OsSharedRealm_nativeIsClosed -979144320
V/REALM_JNI:  --> Java_io_realm_internal_OsSharedRealm_nativeIsClosed -979144320
V/REALM_JNI:  --> Java_io_realm_internal_UncheckedRow_nativeGetIndex -979283168

and the same i got in case after that i switch Internet On and add the item to db.

bit later i found messages:

D/REALM_JAVA: Network request (authenticate): url
D/REALM_JAVA: AuthenticateResponse. Identity 9d83f9775ebba4deac9003d336b9f4c4; Path /account_1
D/REALM_JAVA: Access Token refreshed successfully, Sync URL: 
V/REALM_JNI:  --> Java_io_realm_SyncSession_nativeRefreshAccessToken
D/REALM_JAVA: Scheduling an access_token refresh in 349573 milliseconds

but still no updates on server side


Solution

  • The issue was only in 4.3.0 build and now it fixed in 4.3.2 thank you