Session timeout exception thrown when trying to retrieve data

Hey,

I have just updated the Backendless .NET (Unity) SDK that has to “stay logged in” fixed and it seems to be working correctly in that the user indeed stays logged in and gets logged out when the session time expires.

However, I seem to be getting a session timeout exception thrown where I did not expect it (and didn’t happen before when a user was not logged in)

Basically, I do this call to retrieve all data from a table, which needs to happen regardless if a user is logged in or not and that worked before the fix:

BackendlessAPI.Persistence.DataQueryBuilder dataQueryBuilder = BackendlessAPI.Persistence.DataQueryBuilder.Create();
dataQueryBuilder.SetWhereClause("available = true");
dataQueryBuilder.SetRelationsDepth(1);

IList<BackendlessData.Games> loadedGames = await Backendless.Data.Of<BackendlessData.Games>().FindAsync(dataQueryBuilder);

However, I get an exception that the session is timed out. However, I would expect that these calls could still be done as they’re not really tied to a user.

If this is intended, why does it work when a user is not logged in (before)?

Just in case, this is the stack trace:

BackendlessException: Session timeout. Url: <https://eu-api.backendless.com/CB5F0D27-C339-A133-FFFF-06A6F3EC8700/0A814A5D-1443-47F7-90AE-8B7AD0CC4067/page/session_expiration/index.html>
BackendlessAPI.Engine.Invoker.InvokeSync[T] (System.String className, System.String methodName, System.Object[] args, System.Boolean enableUnderFlowInspection) (at <7bf6c9a1987c4d1a82f01c7b7eb97830>:0)
BackendlessAPI.Service.PersistenceService.Find[T] (BackendlessAPI.Persistence.DataQueryBuilder dataQueryBuilder) (at <7bf6c9a1987c4d1a82f01c7b7eb97830>:0)
BackendlessAPI.Data.DataStoreFactory+DataStoreImpl`1[T].Find (BackendlessAPI.Persistence.DataQueryBuilder dataQueryBuilder) (at <7bf6c9a1987c4d1a82f01c7b7eb97830>:0)
BackendlessAPI.Data.DataStoreFactory+DataStoreImpl`1+<>c__DisplayClass29_0[T].<FindAsync>b__0 () (at <7bf6c9a1987c4d1a82f01c7b7eb97830>:0)
System.Threading.Tasks.Task`1[TResult].InnerInvoke () (at <6073cf49ed704e958b8a66d540dea948>:0)
System.Threading.Tasks.Task.Execute () (at <6073cf49ed704e958b8a66d540dea948>:0)
--- End of stack trace from previous location where exception was thrown ---
BackendlessAPI.Data.DataStoreFactory+DataStoreImpl`1[T].FindAsync (BackendlessAPI.Persistence.DataQueryBuilder queryBuilder) (at <7bf6c9a1987c4d1a82f01c7b7eb97830>:0)
Springloop.OnlineGamesLibrary.LoadGamesManifest (System.Boolean forceReload) (at Assets/Scripts/Games/OnlineGamesLibrary.cs:59)```

Additionally, when I try to work around this and I simply try to log in again, I get another exception:

BackendlessException: The user-token is expired. Login the user again.
BackendlessAPI.Service.UserService.get_CurrentUser () (at <7bf6c9a1987c4d1a82f01c7b7eb97830>:0)
BackendlessAPI.Service.UserService.Login (System.String login, System.String password, System.Boolean stayLoggedIn) (at <7bf6c9a1987c4d1a82f01c7b7eb97830>:0)
BackendlessAPI.Service.UserService+<>c__DisplayClass18_0.<LoginAsync>b__0 () (at <7bf6c9a1987c4d1a82f01c7b7eb97830>:0)
System.Threading.Tasks.Task`1[TResult].InnerInvoke () (at <6073cf49ed704e958b8a66d540dea948>:0)
System.Threading.Tasks.Task.Execute () (at <6073cf49ed704e958b8a66d540dea948>:0)
--- End of stack trace from previous location where exception was thrown ---
BackendlessAPI.Service.UserService.LoginAsync (System.String login, System.String password, System.Boolean stayLoggedIn) (at <7bf6c9a1987c4d1a82f01c7b7eb97830>:0)
Springloop.BackendlessLoginManager.Login (System.String username, System.String password) (at Assets/Scripts/Backend/Backendless/Login/BackendlessLoginManager.cs:77)

Which ironically gets thrown when I try to log in:

BackendlessUser user = await Backendless.UserService.LoginAsync(username, password, true);

Have you tried logging out before login to clear the expired user-token?

I didn’t. But in any real life scenario the user would, or so I assume, be logged out when the token is expired. Not being able to log in after that would be odd, especially since that is literally what is asked in the exception.

An internal ticket has been created: BKNDLSS-29044.
When the problem is fixed, I will report in this thread.

Best Regards, Nikita.

1 Like

Hello, @Joey_Fladderak.

I researched your issue. I have not been able to reproduce these issues.
Login works as it should. The data is retrieved even if I am logged out.

Perhaps something with your application settings?
Try to provide detailed steps to reproduce on a clean project.

Best Regards, Nikita.

Hi @Nikita_Fedorishchev

Odd, but I will see if I can reproduce it in a new / clean project and let you know.

Hi @Nikita_Fedorishchev

I just created a fresh new project with Uniy3D 2021.3.6f1 and imported the latest Backendless Unity Package (6.2.4.0) and I can easily reproduce the issue. (Had to remove the Version Control package, seemed to also give the newtonsoft json issue, even though it was at the latest version)

These are my settings in Backendless:

In Unity, I added the BackendlessPlugin prefab and set the correct App ID and the .NET API Key

In BackendlessPlugin.cs I adjusted the Backendless.URL to the EU cluster:

Backendless.URL = "https://eu-api.backendless.com";

I added this script which represents the table data I have set up in Backendless:

namespace Springloop.BackendlessData
{
	[Serializable]
	public class BackendlessDataObject
	{
		public string objectId;
	}

	[Serializable]
	public class Users : BackendlessDataObject
	{
		public string name;
		public string email;
		public Organisations organisation;
	}

	[Serializable]
	public class Organisations : BackendlessDataObject
	{
		public string name;
		public Packages[] packages;
		public Koepel koepel;
		public OrganisationType type;
	}

	public class OrganisationType : BackendlessDataObject
	{
		public string name;
	}

	public class Koepel : BackendlessDataObject
	{
		public string name;
	}

	[Serializable]
	public class Games : BackendlessDataObject
	{
		public bool available;
		public string gameId;
		public string name;
		public string data;
		public Packages[] packages;
		public Languages[] supportedLanguages;
	}

	[Serializable]
	public class Packages : BackendlessDataObject
	{
		public string name;
	}

	[Serializable]
	public class Languages : BackendlessDataObject
	{
		public string language;
		public string code;
	}
}

And this is the script I run to produce the error:

using BackendlessAPI;
using System.Collections.Generic;
using UnityEngine;

public class BackendTest : MonoBehaviour
{
	protected async void Start()
	{
		BackendlessAPI.Persistence.DataQueryBuilder dataQueryBuilder = BackendlessAPI.Persistence.DataQueryBuilder.Create();
		dataQueryBuilder.SetWhereClause("available = true");
		dataQueryBuilder.SetRelationsDepth(1);

		IList<Springloop.BackendlessData.Games> loadedGames = await Backendless.Data.Of<Springloop.BackendlessData.Games>().FindAsync(dataQueryBuilder);

		Debug.Log($"Loaded {loadedGames.Count} games");

		Login("user@mail.com", "secretPassword"); // mock credentials
	}

	public async void Login(string username, string password)
	{
		BackendlessUser user = await Backendless.UserService.LoginAsync(username, password, true);

		string loggedInUserObjectID = user.ObjectId;

		Springloop.BackendlessData.Users CurrentUser = await Backendless.Data.Of<Springloop.BackendlessData.Users>().FindByIdAsync(loggedInUserObjectID, 2);
	}
}

When I run it for the very first time (in the Unity Editor), games are properly retrieved from the table and the expected “10” gets printed and I am logged in with my user account as expected.

I press stop playing in the Unity Editor.

I wait for 10 seconds (as set in the login properties as the session timeout duration) and run the Unity editor again and I get the exception:

BackendlessException: Session timeout. Url: <https://eu-api.backendless.com/CB5F0D27-C339-A133-FFFF-06A6F3EC8700/0A814A5D-1443-47F7-90AE-8B7AD0CC4067/page/session_expiration/index.html>
BackendlessAPI.Engine.Invoker.InvokeSync[T] (System.String className, System.String methodName, System.Object[] args, System.Boolean enableUnderFlowInspection) (at <7bf6c9a1987c4d1a82f01c7b7eb97830>:0)
BackendlessAPI.Service.PersistenceService.Find[T] (BackendlessAPI.Persistence.DataQueryBuilder dataQueryBuilder) (at <7bf6c9a1987c4d1a82f01c7b7eb97830>:0)
BackendlessAPI.Data.DataStoreFactory+DataStoreImpl`1[T].Find (BackendlessAPI.Persistence.DataQueryBuilder dataQueryBuilder) (at <7bf6c9a1987c4d1a82f01c7b7eb97830>:0)
BackendlessAPI.Data.DataStoreFactory+DataStoreImpl`1+<>c__DisplayClass29_0[T].<FindAsync>b__0 () (at <7bf6c9a1987c4d1a82f01c7b7eb97830>:0)
System.Threading.Tasks.Task`1[TResult].InnerInvoke () (at <e40e5a8f982c4b618a930d29f9bd091c>:0)
System.Threading.Tasks.Task.Execute () (at <e40e5a8f982c4b618a930d29f9bd091c>:0)
--- End of stack trace from previous location where exception was thrown ---
BackendlessAPI.Data.DataStoreFactory+DataStoreImpl`1[T].FindAsync (BackendlessAPI.Persistence.DataQueryBuilder queryBuilder) (at <7bf6c9a1987c4d1a82f01c7b7eb97830>:0)
BackendTest.Start () (at Assets/Scripts/BackendTest.cs:13)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) (at <e40e5a8f982c4b618a930d29f9bd091c>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <4a31731933e0419ca5a995305014ad37>:0)
UnityEngine.UnitySynchronizationContext.Exec () (at <4a31731933e0419ca5a995305014ad37>:0)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at <4a31731933e0419ca5a995305014ad37>:0)

Which originates from this line:

IList<Springloop.BackendlessData.Games> loadedGames = await Backendless.Data.Of<Springloop.BackendlessData.Games>().FindAsync(dataQueryBuilder);

Hope this helps.

Yes, this will help, thanks.

Hello, @Joey_Fladderak.

BackendlessSDK-UnityPackage-6.2.4.1.zip (1.4 MB)
I made some changes before uploading the new version to GitHub.
Can you check if the problem with timeouts is gone?

Best Regards, Nikita.

Hi @Nikita_Fedorishchev

Still getting the same exception sadly.

BackendlessException: Session timeout. Url: <https://eu-api.backendless.com/CB5F0D27-C339-A133-FFFF-06A6F3EC8700/0A814A5D-1443-47F7-90AE-8B7AD0CC4067/page/session_expiration/index.html>
BackendlessAPI.Engine.Invoker.InvokeSync[T] (System.String className, System.String methodName, System.Object[] args, System.Boolean enableUnderFlowInspection) (at <da1d72182baf4d48b59f46ea4942aed5>:0)
BackendlessAPI.Service.PersistenceService.Find[T] (BackendlessAPI.Persistence.DataQueryBuilder dataQueryBuilder) (at <da1d72182baf4d48b59f46ea4942aed5>:0)
BackendlessAPI.Data.DataStoreFactory+DataStoreImpl`1[T].Find (BackendlessAPI.Persistence.DataQueryBuilder dataQueryBuilder) (at <da1d72182baf4d48b59f46ea4942aed5>:0)
BackendlessAPI.Data.DataStoreFactory+DataStoreImpl`1+<>c__DisplayClass29_0[T].<FindAsync>b__0 () (at <da1d72182baf4d48b59f46ea4942aed5>:0)
System.Threading.Tasks.Task`1[TResult].InnerInvoke () (at <e40e5a8f982c4b618a930d29f9bd091c>:0)
System.Threading.Tasks.Task.Execute () (at <e40e5a8f982c4b618a930d29f9bd091c>:0)
--- End of stack trace from previous location where exception was thrown ---
BackendlessAPI.Data.DataStoreFactory+DataStoreImpl`1[T].FindAsync (BackendlessAPI.Persistence.DataQueryBuilder queryBuilder) (at <da1d72182baf4d48b59f46ea4942aed5>:0)
BackendTest.Start () (at Assets/Scripts/BackendTest.cs:15)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) (at <e40e5a8f982c4b618a930d29f9bd091c>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <4a31731933e0419ca5a995305014ad37>:0)
UnityEngine.UnitySynchronizationContext.Exec () (at <4a31731933e0419ca5a995305014ad37>:0)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at <4a31731933e0419ca5a995305014ad37>:0)

Quite an interesting situation is obtained. I still can’t reproduce your problem.
Tried synchronous/asynchronous requests + classes/maps. Everything works as expected.
Why is your URL path pointing to index.html maybe that’s the problem?

Those are always lovely!

I have not set up anything (to my knowledge) to point to index.html. The only URL I changed in code is the Backendless.URL to point to the EU where the app (cluster) is hosted.

Which would be

Backendless.URL = "https://eu-api.backendless.com";

Which I adjusted in BackendlessPlugin.cs

Yes, but something is forcing your application to refer to it.
Try to create a pure application in the console (Backendless).
Then create a clean application in Unity and import backendless there.
Replace your scene with the imported one. And set the URL to eu(dont forget set App ID and API Key).
After that, try running the application.
Then try adding your logic little by little. Start with a regular login. And so, until we can figure out what exactly causes this error.

Alright, will try that.

I will try this on Wednesday (I have the day off tomorrow) and I will let you know what happens.

Good. I changed the logic a bit. If the User-Token was expired, then you had to logout yourself and log in again. I slightly changed the principle of operation, now instead of an error, a logout occurs. So there should be no more problems with the User-Token.

Hi @Nikita_Fedorishchev

I did what you asked and created a new console project (Springloop_Test) and I am still getting the exception. The only things I did to make make it work is the following:

  • Added a new user to the User table
  • Added a Games table (no further adjustments)
  • Enabled ‘Enable Session Timeout’ and set it to 10 seconds to test out.

Within the 10 seconds (the session) everything works as expected, but after 10 seconds (when the session is timed out) I get the exception again:

BackendlessException: Session timeout. Url: <https://eu-api.backendless.com/273A996E-CB04-C089-FFA1-1521874D9600/C0677650-7BC7-4DB9-B811-7369D137B9CE/page/session_expiration/index.html>
BackendlessAPI.Engine.Invoker.InvokeSync[T] (System.String className, System.String methodName, System.Object[] args, System.Boolean enableUnderFlowInspection) (at <da1d72182baf4d48b59f46ea4942aed5>:0)
BackendlessAPI.Service.PersistenceService.Find[T] (BackendlessAPI.Persistence.DataQueryBuilder dataQueryBuilder) (at <da1d72182baf4d48b59f46ea4942aed5>:0)
BackendlessAPI.Data.DataStoreFactory+DataStoreImpl`1[T].Find () (at <da1d72182baf4d48b59f46ea4942aed5>:0)
BackendlessAPI.Data.DataStoreFactory+DataStoreImpl`1[T].<FindAsync>b__28_0 () (at <da1d72182baf4d48b59f46ea4942aed5>:0)
System.Threading.Tasks.Task`1[TResult].InnerInvoke () (at <e40e5a8f982c4b618a930d29f9bd091c>:0)
System.Threading.Tasks.Task.Execute () (at <e40e5a8f982c4b618a930d29f9bd091c>:0)
--- End of stack trace from previous location where exception was thrown ---
BackendlessAPI.Data.DataStoreFactory+DataStoreImpl`1[T].FindAsync () (at <da1d72182baf4d48b59f46ea4942aed5>:0)
BackendTest.Start () (at Assets/Scripts/BackendTest.cs:9)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) (at <e40e5a8f982c4b618a930d29f9bd091c>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <4a31731933e0419ca5a995305014ad37>:0)
UnityEngine.UnitySynchronizationContext.Exec () (at <4a31731933e0419ca5a995305014ad37>:0)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at <4a31731933e0419ca5a995305014ad37>:0)

I simply press play in the Unity Editor, Stop, Press play again after 10 seconds (or until the error shows at least)

I have attached the Unity project in which I am testing this. Perhaps it might shed some light on this and hopefully enables you to reproduce the issue.

backendlessTests.zip (2.2 MB)

1 Like

Hello, @Joey_Fladderak.

I seem to understand what the problem is, it will take some time. I will write to you in this thread.
By the way, did you try disable timeout, then everything works fine?

Hi @Nikita_Fedorishchev,

Great to hear you found something out. Everything works fine when I disable the timeout and I can work without it for now.

However, when I first enable the timeout, get the session expired exception, disable timeout, then I still get the exception I need to log in again.

Hello, @Joey_Fladderak.

Can you try this one?
BackendlessSDK-UnityPackage-6.2.4.1v2.zip (1.4 MB)
I reproduced your issue for RT. After the changes, I don’t see the error anymore. Hope this helps.

Best Regards, Nikita.