InvalidSession error returned after some days disconnected

Hi @Ian_Ward

I’m receiving message InvalidSession in windows version of app but when use Android version they work ok.

Xamarin. Forms 5
Realm SDK .Net 10.4.1

Attached Realm site listing image with duplicated users.
After image LOG messages.

error occurs at :

await App.AppEnvironmentService.SyncDB.RealmInstance.GetSession().WaitForDownloadAsync()

Before this is send to server Request. (POST “”)

Message=A system error occurred while waiting for completion. See InnerException for more details
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Realms.Sync.SessionHandle.d__8.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at LexSemanticClient.ViewModel.LoginViewModel.d__81.MoveNext() in C:\Users\scf\Source\Repos\Utilities\LexSemanticClient\LexSemanticClient\ViewModel\LoginViewModel.cs:line 624
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at LexSemanticClient.ViewModel.LoginViewModel.d__77.MoveNext() in C:\Users\scf\Source\Repos\Utilities\LexSemanticClient\LexSemanticClient\ViewModel\LoginViewModel.cs:line 540
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at LexSemanticClient.Services.AppEnviromentService.d__129.MoveNext() in C:\Users\scf\Source\Repos\Utilities\LexSemanticClient\LexSemanticClient\Services\AppEnviromentService.cs:line 369
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at LexSemanticClient.Views.Pages.VerbeteSearchPage.<VerbeteSearchPage_Appearing>d__25.MoveNext() in C:\Users\scf\Source\Repos\Utilities\LexSemanticClient\LexSemanticClient\Views\Pages\VerbeteSearchPage.xaml.cs:line 165

Inner Exception 1:
SessionException: InvalidSession


2021-09-07 21:31:15.024 Debug: Realm sync client ([realm-core-11.3.1])
2021-09-07 21:31:15.119 Debug: Supported protocol versions: 2-3
2021-09-07 21:31:15.122 Debug: Platform: Windows WindowsUniversal unknown 10.0 x86_64
2021-09-07 21:31:15.126 Debug: Build mode: Release
2021-09-07 21:31:15.128 Debug: Config param: max_open_files = 256
2021-09-07 21:31:15.131 Debug: Config param: one_connection_per_session = true
2021-09-07 21:31:15.133 Debug: Config param: connect_timeout = 120000 ms
2021-09-07 21:31:15.135 Debug: Config param: connection_linger_time = 30000 ms
2021-09-07 21:31:15.137 Debug: Config param: ping_keepalive_period = 60000 ms
2021-09-07 21:31:15.142 Debug: Config param: pong_keepalive_timeout = 120000 ms
2021-09-07 21:31:15.145 Debug: Config param: fast_reconnect_limit = 60000 ms
2021-09-07 21:31:15.149 Debug: Config param: disable_upload_compaction = false
2021-09-07 21:31:15.152 Debug: Config param: tcp_no_delay = false
2021-09-07 21:31:15.155 Debug: Config param: disable_sync_to_disk = false
2021-09-07 21:31:15.158 Debug: User agent string: 'RealmSync/11.3.1 (Windows WindowsUniversal unknown 10.0 x86_64)

hey @Sergio_Carbonete - what kind of windows app is this ? You mention Xamarin - so is this the iOS version of the same app that works on Android or something else entirely?!

Hi @Ian_Ward , Windows UWP and Andoid , both same code using Xamarin Forms 5.

More info, My app work with more than User, switch between users. I change code to go login with error occurs, and is possible to login with other user. But it’s not possible get CustomData from first user receiving same error InvalidSession: invalid session: refresh token expired.
code: user.GetCustomData();


I’m confused - are you saying that the original InvalidSession error that you were hitting for Windows is now resolved and you are getting a new error with custom user data now?

@Ian_Ward sorry for confusion, problem not resolved, InvalidSession occurs for individual User, if i made login with another user(B) it’s ok. But if i try access data from first user (A) problem continuous.

I have a listview to admin all logged users, one(A) can’t access custom data receive InvalidSession and other (B) read ok.

Per the error message - it appears that user A’s refresh token expired. This means the user needs to reauthenticate in order to obtain a new refresh token. It’s a bug that the user wasn’t logged out automatically - we’ll resolve this in a future release, but for now you can just log the user out and then log them back in.

Hi @nirinchev ,

  1. I have a problem to automatic login, same app/user can be in different devices and OS. I can’t store mail/password locally, i use mail/password credential provider. Because they can change password in other device.
    Exist any LoginAsync method with Realm User stored in local Realm as parameter ?
    Need to register this problem at github ?

  2. Duplicate user’s at User page admin at, is the same problem or another team will take it ?


  1. You shouldn’t be storing credentials for the user. Instead, you should display a message saying their session has expired and they should re-enter their credentials.
  2. The screenshot you’ve attached shows that the user IDs are truncated. My guess is that the final part of the IDs are different. You can verify that by clicking the copy button next to the ID and pasting it in some text editor.
  1. this is very unhappy to user. How many time token lives ?
    When you think this issue will resolved?

  2. They are same ID, and create date is the same.


@Sergio_Carbonete Can you share a code snippet for how you are logging in, opening the realm, and then checking that the user has logged in previously (and therefore can just use the cached user)

Hi @Ian_Ward ,
To know what user is logged - realmUser = RealmApp.CurrentUser;

To register new user - await RealmApp.EmailPasswordAuth.RegisterUserAsync(mail, password);

To create instance

realmInstance = online ? await Realm.GetInstanceAsync(RealmSyncConfig) : Realm.GetInstance(RealmSyncConfig);

Most diferent thing i do is start/stop sync after app load.

 if (Connectivity.NetworkAccess == NetworkAccess.Internet)
		await Task.WhenAll(App.AppEnvironmentService.SyncDB.RealmInstance.GetSession().WaitForDownloadAsync(),

@Sergio_Carbonete How are you checking that you’ve already logged in before and downloaded the realm? Usually this is done with a check

if (CurrentUser() != null) { Realm.GetInstance()}

//make a login attempt and then open the realm

Also why are you pausing the sync? I wonder if that has something to do with it

Hi @Ian_Ward

test = GetAllUsers().Count() == 0

Stop because especific characteristic of some client connection and type of payment.

When i turn development mode off duplicate users gone for a while, returning to showing.