When open app and put idle for 10 mint, sync realm give "invalid session" error on realm ui Log tab

When opening the app and put idle for 10 mint, sync realm give “invalid session” error on realm UI Log tab

1 Like

@rakesh_dadhich Are you able to sync once you start using the app again?

Hello,
I do have the same issue, don’t know what it could be about.
@Ian_Ward could you please share a bit more information about syncing? Could that fix the problem?

The Realm SDK will handle refreshing the access token for you but if the app is backgrounded and goes inactive then you may get an invalid session error at first when the app goes back into the foreground. Once it gets this error it should automatically obtain a new access token

Thanks for the quick reply!

When the app tries to make a call when going back into the foreground, we get the following:

{
    "error": "invalid session",
    "error_code": "InvalidSession",
    "link":"XXX"
}

Followed by two more calls, which seem to do what you describe:

Request 1
:method: POST
:scheme: https
:authority: eu-west-1.aws.stitch.mongodb.com
:path: /api/client/v2.0/auth/session

Request 2
:method: DELETE
:scheme: https
:authority: eu-west-1.aws.stitch.mongodb.com
:path: /api/client/v2.0/auth/session

However, both result in a 401 and the app gets stuck.

Are we missing something, or is there a recommended way to handle this situation?

Thank you!

Are you able to reproduce this reliably? If so, can you upload a sample app and open a support ticket so we can sort this out for you?

*with app we mean progressive web application, so using the realm web sdk.

Will look into creating a support ticket, thanks!

Hi, I also had this problem today, which caused my Electron application to crash and not open again. I was able to open the application properly after deleting the mongodb-realm folder

And I think the reproduce of this bug is when the application is idle for a long time and the network is down or unstable during this period

We have a similar issue with Android devices. I deleted all users in Realm -> App Users and on iOS new user ID was issued when I deleted and installed the app but on Android it always uses the same user ID and it always fails with invalid session. Not sure if related to user ID but it looks like that.

We tried to delete realm files using different methods but the user ID stays the same and it looks like the user with this ID can’t be created anymore for some reason.

Hey Folks, we are in the process of improving our token refresh logic to handle this automatically. For now, you should be able to call login() with a user and continue syncing to workaround this behavior

1 Like

@Ian_Ward this issue is resolved ? I’m receiving message InvalidSession in windows version of app but when use Adnroid version they work ok.

error occurs at :
 await App.AppEnvironmentService.SyncDB.RealmInstance.GetSession().WaitForDownloadAsync()

Realms.Exceptions.RealmException
  HResult=0x80131500
  Message=A system error occurred while waiting for completion. See InnerException for more details
  Source=System.Private.CoreLib
  StackTrace:
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Realms.Sync.SessionHandle.<WaitAsync>d__8.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at LexSemanticClient.ViewModel.LoginViewModel.<WaitSync>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.<HasAuthSaved>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.<OpenAsyncDB>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

Last event registered before is

Request. (POST “https://realm.mongodb.com/api/client/v2.0/auth/session”)

Wow perfect timing - Fix refreshing access token on UI thread by cmelchior · Pull Request #7552 · realm/realm-java · GitHub

Should be resolved in the latest version.

I put 10.4.1 .net version and problem continue the same.
May be it’s not a sdk problem, i see users duplicated at REALM dashboard.

@Sergio_Carbonete Yours seems like a completely a separate issue from the problem the other users on this thread have experienced. Can you please open a separate forum post with corresponding details for your specific problem? Client side logs from app startup would be helpful. Tag me and I will take a look.

ok opened InvalidSession error returned after some days disconnected

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.