suriyun-mmorpg / UnityMultiplayerARPG_DatabaseManager

A MMORPG KIT's database manager project written by using .NET8
MIT License
2 stars 2 forks source link

Connection Rejected by server due to Accestoken #3

Closed Callepo closed 10 months ago

Callepo commented 11 months ago

@insthync image

When 2 clients connected, this error is thrown in databasemanager Console

Callepo commented 11 months ago

https://github.com/suriyun-mmorpg/UnityMultiplayerARPG_DatabaseManager/assets/7702658/5e12a662-be45-4e04-a7a5-e28c4f7ef787

image

Callepo commented 11 months ago

@insthync Tested with Mysql also, it throws the Invalid Acces Token there too, but obviously net the Nested transaction error from sqlite. it just shows acces token issue now.

Mysql DB image

Callepo commented 11 months ago

@insthync oh i should mention this is on a Server ( Linux Build) Local it happens also but not as easy.. you have to keep logging in/ logging out for a while, 2 accounts open and then it gets the error

[Local clients connected to local server] image

IDK if 2 accounts is even the issue, but thats how i can reproduce it faster

insthync commented 11 months ago

Error log for mysql please

Callepo commented 11 months ago

@insthync when using mysql the databasemanager doesnt show any error like the SQLite did, just central creates a log file with acces token issue. ill try and debug it and see if i can catch an error

Callepo commented 11 months ago

@insthync The update user count throw the same error as the 2 other ones we fixed before where the value wasnt nullable image

Ill see what else i can find

Callepo commented 11 months ago

@insthync image image

2nd one for Validate Acces Token

Callepo commented 11 months ago

@insthync ERROR RestDatabaseClient [2023-10-02 13:44:52] - Cannot UpdateCharacterAsync status: 500 ERROR MapNetworkManager(MapNetworkManager) [2023-10-02 13:45:12] - Invalid access token for user: ERROR No Tag [2023-10-02 13:45:22] - Can't deserialize content: , Newtonsoft.Json.JsonSerializationException: No JSON content found and type 'MultiplayerARPG.MMO.CharacterResp' is not nullable. Path '', line 0, position 0. at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) [0x000db] in <29e3dfd7379d434ca9881f8263fe42fe>:0 at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00054] in <29e3dfd7379d434ca9881f8263fe42fe>:0 at Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in <29e3dfd7379d434ca9881f8263fe42fe>:0 at Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) [0x0002d] in <29e3dfd7379d434ca9881f8263fe42fe>:0 at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in <29e3dfd7379d434ca9881f8263fe42fe>:0 at UnityRestClient.RestClient+Result`1[T]..ctor (System.Int64 responseCode, System.Boolean isHttpError, System.Boolean isNetworkError, System.String stringContent, System.String error) [0x00044] in <9ae98d53e4264ad78b3cc0b287e7ff7f>:0

Callepo commented 11 months ago

@insthync Rebuild all new again, test from the start

image

this is what central logs And this is databasemanager image

Seems the process from db is going fine, its send okObjectsSesult back as a Response to client..

but the response is False.

image

client is getting False. so player cant start game..

so the accestoken is being for some reason wiped or cant be read

but in the DB image

its there.. so i thought it was maybe not caching properly so i put disabled caching on, and tried again.. it still giving the connection rejected from server.

So i think the mapnetworkmanager is sending wrong assestoken to the db to be checked, or its putting the value as null And when the db tries to validate it will be false.

Callepo commented 11 months ago

@insthync im debugging the client to see which Acces token its sending back to server and i noticed when you press Exit in game, game loads home scene, and prints out acces token 1 time.. But sometimes it prints it out 2 times in a row..

When it does this 2 times, thats when you get connection rejected image

Its sending 2 request to server OR server is processing the Exit 2 times and sending back 2 responses, and each process changes the token, so the 2nd change was on server making the token different than what the client has

Callepo commented 11 months ago

@insthync

https://github.com/suriyun-mmorpg/UnityMultiplayerARPG_DatabaseManager/assets/7702658/346aae18-3177-4f68-915a-aae1a3220f09

My Debug is inside OnCentralConnected image

Callepo commented 11 months ago

https://github.com/suriyun-mmorpg/UnityMultiplayerARPG_DatabaseManager/assets/7702658/c97a9aa3-cef1-49c6-bd11-481fba8f3150

When logout, Db acces token is same as Debug log, when it print it out 2 times, when the connection rejected occurs.. The Db acces token is different from client

Callepo commented 11 months ago

@insthync

Callepo commented 11 months ago

Db manager get 2 request to validate acces token b2b, which makes it update the token in the db. image

Look at the top and at the bottom, should only be 1 request and done. but Central server send 2 request, or Databasemanager thinks it got 2 for some reason

Callepo commented 10 months ago

@insthync ?

insthync commented 10 months ago

?

insthync commented 10 months ago

Did you find why UIMmoSceneHome -> OnCentralServerConnected called twice, all this problem is not because of database manager at all.

If you can't find it, then easiest way to fix it is just not update access token when validate access token, do it by delete CentralNetworkManager_Login -> HandleRequestValidateAccessToken -> UpdateAccessTokenAsync

insthync commented 10 months ago

When you write the access token log, did you try to find a difference from its stack trace ?

insthync commented 10 months ago

And you don't have to tag me, it is already notified and send me an email.

Callepo commented 10 months ago

Did you find why UIMmoSceneHome -> OnCentralServerConnected called twice, all this problem is not because of database manager at all.

If you can't find it, then easiest way to fix it is just not update access token when validate access token, do it by delete CentralNetworkManager_Login -> HandleRequestValidateAccessToken -> UpdateAccessTokenAsync

removing it would fix the issue yes, but is there a specific reason why the accestoken was being changed everytime u press Exit ingame, instead only setting it once when u initially log in ?

And also this issue only happens when using the NET7 Services, not when running it the normal way. Even tho the same process is happening there. And yes, i said either central is calling it twice, or db manager thinks its receiving it twice. didnt fully know which one of the 2 it was precise.

Callepo commented 10 months ago

When you write the access token log, did you try to find a difference from its stack trace ?

no i didnt. ill try and see if i can

insthync commented 10 months ago

Did you find why UIMmoSceneHome -> OnCentralServerConnected called twice, all this problem is not because of database manager at all. If you can't find it, then easiest way to fix it is just not update access token when validate access token, do it by delete CentralNetworkManager_Login -> HandleRequestValidateAccessToken -> UpdateAccessTokenAsync

removing it would fix the issue yes, but is there a specific reason why the accestoken was being changed everytime u press Exit ingame, instead only setting it once when u initially log in ?

And also this issue only happens when using the NET7 Services, not when running it the normal way. Even tho the same process is happening there. And yes, i said either central is calling it twice, or db manager thinks its receiving it twice. didnt fully know which one of the 2 it was precise.

Because OnCentralServerConnected is called twice, and in that function, it calls a function to validate the access token, and then when the validating it will change to a new access token, so the problem occurs.

insthync commented 10 months ago

You may include Time.framecount in the log message to see if it is being called in the same frame or not.

I think I will remove the update access token in the validate function because it is actually not necessary.

Callepo commented 10 months ago

Did you find why UIMmoSceneHome -> OnCentralServerConnected called twice, all this problem is not because of database manager at all. If you can't find it, then easiest way to fix it is just not update access token when validate access token, do it by delete CentralNetworkManager_Login -> HandleRequestValidateAccessToken -> UpdateAccessTokenAsync

removing it would fix the issue yes, but is there a specific reason why the accestoken was being changed everytime u press Exit ingame, instead only setting it once when u initially log in ? And also this issue only happens when using the NET7 Services, not when running it the normal way. Even tho the same process is happening there. And yes, i said either central is calling it twice, or db manager thinks its receiving it twice. didnt fully know which one of the 2 it was precise.

Because OnCentralServerConnected is called twice, and in that function, it calls a function to validate the access token, and then when the validating it will change to a new access token, so the problem occurs.

Correct, i understand, But what would be the reason it only happens with the Net7 Services? cuase the same codes are there for the Unity Server too

And what was the original Reason the accestoken was set to change everytime we validate the token? was this needed for something? and removing the update part would cuase an issue? or it was just done for no reason,

Callepo commented 10 months ago

You may include Time.framecount in the log message to see if it is being called in the same frame or not.

I think I will remove the update access token in the validate function because it is actually not necessary.

ah ok ok, u already answered the Validate question here, cool, removing it would fix the issue we have tho yes

insthync commented 10 months ago

Maybe .Net service is faster and access token is changed before the next request.