Error Invalid Session on Old Client 10.3 or 10.4

I update Xamarin App with 10.5.0. After my first connection with my test smartphone all client with 10.3 or 10.4 have Realm Exception with InnerExecption: Invalid Session.
Unique solution: delete app and reinstall !!!

Why? What appens?

Please Help me, I have 3k user and I don’t want to ask all to remove App


                    Realm realm = Realm.GetInstance(config);                        
                    Session session = realm.GetSession();                        
                    await session.WaitForDownloadAsync();

I obtain:

A system error occurred while waiting for completion. See InnerException for more details Errore InnerException: InvalidSession

I try also Realm.Delete(config)… nothing

Only remove App and reinstall works because removing app delete local realm…
Please help me

This sounds like a production issue you have with sync - it’s best to open a support ticket and have the team investigate.

I have a free plan… only chat both… i try to delete file realm:

config = new SyncConfiguration(partition, user);

File.Delete(config.DatabasePath); //terrible!!!

realm = await Realm.GetInstanceAsync(config);

any suggestion?

File.Delete not solve problem… InvalidSession… OldSession is stored on device? Can I restart session?

The “Invalid Session” error means that the user is not authenticated - it is thrown by the server and is unrelated to the sync session, despite the similar naming. Can you check out the server logs for any indication as to what might be the reason behind this.

1 Like

I use on anonimous user

I find this error:


Ending session with error: integrating changesets failed: could not complete upload integration as this connection no longer owns the file ident; no action is needed, as the client has already established a new connection to the sync server to complete its upload (ProtocolErrorCode=101)


[ “Session was active for: 13s” ]



Session Metrics:

{ “uploads”: 4, “downloads”: 4 }

Remote IP Address:


Realm .NET v10.3.0

Platform Version:


Why remove app and reinstall all is ok? No code change, only remove and reinstall.
Is user session cached in client file system?

Per the docs, anonymous users’ refresh token is valid for 60 days. When the token expires, the anonymous user is logged out and the user on the device is invalidated.

The issue you’re seeing is likely these users that logged in 2 months ago are expiring right now and they can no longer synchronize. This is what the “Invalid Session” error is caused by and it only affects users that logged in 2 months ago (but will keep happening in a rolling 2-month window). The reason why this breaks your app though is due to this bug - instead of logging the user out on token expiration, we still return it from app.CurrentUser or app.LoginAsync(Credentials.Anonymous()). I’ll ping the team to prioritize fixing it.

The reason why deleting the app works is that this deletes the Realm that stores the user metadata - it’s unrelated to the Realm you’re interfacing with. This deletes the invalid user and you can login with a new user that will be valid for another 60 days. You can achieve the same by subscribing to the Session.Error event and looking at the SessionException.ErrorCode and logging out the user if the error code is BadAuthentication:

Session.Error += (s, e) =>
    if (e is SessionException sessionEx && sessionEx.ErrorCode == ErrorCode.BadUserAuthentication)
        // User token was expired - log them out
        var session = (Session)s;
        _ = session.User.LogOutAsync();
        // Redirect user to main screen and reauthenticate

This is obviously not great, which is why I’ve reached out to the cloud team to see if we can remove the expiration for anonymous users’ refresh tokens. Even if we do that, your current users’ refresh tokens have an expiry date, so it might be a good idea to add the temporary workaround code that I shared above.

1 Like

Nikola you are God!!!

If I want publish a release that solve problem simply update the app from store, can I logout always User and reconnect? Or I have to intercept error as in your sample code?

If you always log out the user, you’ll have to redownload everything on every app start, which is probably going to be pretty bad UX. I’d recommend using the code I posted as that should only happen once every 2 months. And again, we’ll try to remove the token expiration for anonymous users and fix the linked realm-core issue that will make this code unnecessary.


Ok, I try to update my code with your sample code.
If you remove token expiration please tell me


After few hours, not GetInstanceAsync stuck…

please help!

I use a email/passoword user but nothing, GetInstanceAsync log connected, but stuck

No, sorry I use a email/passoword and GetInstanceAsync works, with Anonymous not works

I will go crazy… with a single simbolic email/password used internally for all app, GetInstanceAsync stuck… after a few attempts it works … why?

How does it get stuck? Keep in mind that if you have a lot of data, it may take a while for a new user to download things. Also, can you bump the logging level and check if there’s actually any activity in the logs? You do it by setting Realms.Logging.Logger.LogLevel = Realms.Logging.LogLevel.Detail.

data is always few.
Until yesterday GetInstanceAsync took a few seconds …
now 3-4 minutes the first time, then a few seconds, why?

GetInstanceAsync needs to download all the data that is not on the device. If you had logged in previously, you would only download recent changes, but a new user needs to download everything from scratch. My guess is that you have a lot of data that needs to be transferred to the device, but you weren’t seeing that previously because you were only downloading incremental changes. You can check the amount of data that is being downloaded by adding an OnProgress callback to your sync configuration. You can log the amount of data that needs to be downloaded as well as the download progress to get a sense of how much time it’ll take for GetInstanceAsync to complete.

With LogLevelDetail:

2021-09-17 16:45:00.845580+0200 Talk.iOS[45415:867097] 2021-09-17 14:45:00.834 Detail: Connection[1]: Session[1]: Binding ‘/Users/luigi/Library/Developer/CoreSimulator/Devices/C85ADBD1-80E2-407F-915B-5CC413BF9E11/data/Containers/Data/Application/7ED4CE82-E73A-42CF-91BA-756AD71B1E9E/Documents/mongodb-realm/talkapp-mtmlp/6144912e063503f6b4297220/s_cs.realm’ to ‘“cs”’
2021-09-17 16:45:00.845978+0200 Talk.iOS[45415:867097] 2021-09-17 14:45:00.845 Info: Connection[1]: Session[1]: client_reset_config = false, Realm exists = false, client reset = false
2021-09-17 16:45:00.861385+0200 Talk.iOS[45415:867097] 2021-09-17 14:45:00.861 Detail: Connection[1]: Resolving ‘
2021-09-17 16:45:00.863623+0200 Talk.iOS[45415:867097] 2021-09-17 14:45:00.863 Detail: Connection[1]: Connecting to endpoint ‘’ (1/1)
2021-09-17 16:45:00.959446+0200 Talk.iOS[45415:867097] 2021-09-17 14:45:00.959 Info: Connection[1]: Connected to endpoint ‘’ (from ‘’)
2021-09-17 16:45:01.447078+0200 Talk.iOS[45415:867097] 2021-09-17 14:45:01.446 Detail: Connection[1]: Negotiated protocol version: 3
2021-09-17 16:48:26.172064+0200 Talk.iOS[45415:866586] Realm is located at: /Users/luigi/Library/Developer/CoreSimulator/Devices/C85ADBD1-80E2-407F-915B-5CC413BF9E11/data/Containers/Data/Application/7ED4CE82-E73A-42CF-91BA-756AD71B1E9E/Documents/mongodb-realm/talkapp-mtmlp/6144912e063503f6b4297220/s_cs.realm

Last row is my log at end of GetInstanceAsync