Search Unity

Bug Lobby events (live updates) stops working after switching to another player account

Discussion in 'Lobby' started by lsaeteurn, Jul 14, 2023.

  1. lsaeteurn

    lsaeteurn

    Joined:
    Jan 26, 2023
    Posts:
    93
    If I joined a lobby and leave that lobby, then I log out of my player's account and onto another one, lobby events stops working. When I log back into the first account, lobby events starts functioning again.

    There appears to be a bug with switching player accounts. The lobby does not properly clean up after disconnecting. The first player account that connects to the service will be the only account that works.

    I think this is a bug with Lobby service. Has anyone else had this issue? Is there a method I need to call to clean up the Lobby service properly?

    I'm using the latest version of Lobby (1.1.0-pre.5).

    Here is the stack trace:
    RequestFailedException: unauthorized
    Unity.Services.Wire.Internal.CommandManager.WaitForCommandAsync (System.UInt32 id) (at ./Library/PackageCache/com.unity.services.wire@1.1.8/Runtime/Centrifuge/CommandManager.cs:55)
    Unity.Services.Wire.Internal.Client.SendCommandAsync (System.UInt32 id, Unity.Services.Wire.Protocol.Internal.Command command) (at ./Library/PackageCache/com.unity.services.wire@1.1.8/Runtime/Centrifuge/Client.cs:114)
    Unity.Services.Wire.Internal.Client.SubscribeAsync (Unity.Services.Wire.Internal.Subscription subscription) (at ./Library/PackageCache/com.unity.services.wire@1.1.8/Runtime/Centrifuge/Client.cs:581)
    Unity.Services.Wire.Internal.Client+<>c__DisplayClass40_0.<CreateChannel>b__1 (System.Threading.Tasks.TaskCompletionSource`1[TResult] completionSource) (at ./Library/PackageCache/com.unity.services.wire@1.1.8/Runtime/Centrifuge/Client.cs:612)
    Unity.Services.Lobbies.Internal.LobbyChannel.SubscribeAsync () (at ./Library/PackageCache/com.unity.services.lobby@1.1.0-pre.5/Runtime/SDK/LobbyUpdates/Internal/LobbyChannel.cs:50)
    Rethrow as LobbyServiceException: There was an error when trying to connect to the lobby service for events. Ensure a valid Lobby ID was sent. Error Code[23007].
    Unity.Services.Lobbies.Internal.LobbyChannel.SubscribeAsync () (at ./Library/PackageCache/com.unity.services.lobby@1.1.0-pre.5/Runtime/SDK/LobbyUpdates/Internal/LobbyChannel.cs:59)
    Unity.Services.Lobbies.Internal.WrappedLobbyService.SubscribeToLobbyEventsAsync (System.String lobbyId, LobbyEventCallbacks lobbyEventCallbacks) (at ./Library/PackageCache/com.unity.services.lobby@1.1.0-pre.5/Runtime/SDK/WrappedLobbyService.cs:98)
     
  2. Mj-Kkaya

    Mj-Kkaya

    Joined:
    Oct 10, 2017
    Posts:
    179
  3. lsaeteurn

    lsaeteurn

    Joined:
    Jan 26, 2023
    Posts:
    93
    I'm not sure you're understanding the problem I'm describing. The issue is not with lobbies themselves, but with the new Lobby Events features connected via Wire. Switching lobbies work fine. The issue is with logging out of Player Accounts and logging into a different account. The real-time Lobby Events no longer functions because it thinks I'm a different Player Account and fails to authenticate.
     
  4. arnaud_gout

    arnaud_gout

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    26
    Hey lsaeteurn,
    I'm working on the Wire package, thanks for reaching out!
    I will need more data to understand what is going on, but indeed, changing identity mid game wasn't a use case for us until recently.
    Can you please setup a define to activate Wire extended logging?
    You just have to go to your Player Settings, and add ENABLE_UNITY_WIRE_VERBOSE_LOGGING to the scripting define symbols.
    Then show us the logs please :)
     
  5. lsaeteurn

    lsaeteurn

    Joined:
    Jan 26, 2023
    Posts:
    93
    Okay, here is the log. If you need more detail, let me know.

    part 1.png part 2.png
     
  6. lsaeteurn

    lsaeteurn

    Joined:
    Jan 26, 2023
    Posts:
    93
    1st Subscribe command:
    [Wire]: sending SUBSCRIBE command: {"id":3,"subscribe":{"channel":"$lobby!!!YNNBvPeMf69Xq9okv3QJ8S!!!7c4cd2f0-dff8-413c-99be-0b65811f0679!!!4ed646cd-a399-4f1b-9b14-865b8d78ac8a","token":"eyJhbGciOiJSUzI1NiIsImtpZCI6IkxvYmJ5OmQ4MGM1ZjU0LWM0NjAtNDQ5Zi04ZjlmLTk1MjRhNzIzYTdkYSIsInR5cCI6IkpXVCJ9.eyJlbnZpcm9ubWVudElkIjoiNGVkNjQ2Y2QtYTM5OS00ZjFiLTliMTQtODY1YjhkNzhhYzhhIiwiZXhwIjoxNjg5NjIxMTY5LCJpYXQiOjE2ODk2MTc1NjksImlzcyI6ImxvYmJ5IiwibmJmIjoxNjg5NjE3NTY5LCJwcm9qZWN0SWQiOiI3YzRjZDJmMC1kZmY4LTQxM2MtOTliZS0wYjY1ODExZjA2NzkiLCJyZXNvdXJjZSI6IllOTkJ2UGVNZjY5WHE5b2t2M1FKOFMiLCJzZXJ2aWNlSWQiOiJsb2JieSIsInN1YiI6IjRKSHYyaGNCZFpMTVBqRnNwaHFzaGpsM0hEbHkifQ.erHCUhEeBDl49tgCHvB0e6y4hZ9a5JNTJ3wLCqevwxlbrGePw4CeqjYyMurv6qGviwm6R26o41qdtOmCrjRXaAcIgC6ycxFNDk_i9AWa0Ad0TYwNO_xFFSXikhrBbdJP5yaNAEczoSLGXXV9gFBSlYl4B1Kw2JHnlX6d-blO8GTtBfhl5v9hTyZSIkaGvRgKMzl_8dJvDOuykut1hPTsissVo3CK65-nUWDLvg-24vxixVDB7o1pZxGd5G59a0LWfCNLFVTep_IF59GoSLhCqa2t4Rh6R24nak4lqR4y4a_a0-lxnEXZGhkM0R7oRFRFyMQLeXzo7bLDSJgUdsvy1Q","recover":false,"offset":0}}

    2nd Subscribe command:
    [Wire]: sending SUBSCRIBE command: {"id":10,"subscribe":{"channel":"$lobby!!!23U3tQdXMnbmydpZZHYknb!!!7c4cd2f0-dff8-413c-99be-0b65811f0679!!!4ed646cd-a399-4f1b-9b14-865b8d78ac8a","token":"eyJhbGciOiJSUzI1NiIsImtpZCI6IkxvYmJ5OmQ4MGM1ZjU0LWM0NjAtNDQ5Zi04ZjlmLTk1MjRhNzIzYTdkYSIsInR5cCI6IkpXVCJ9.eyJlbnZpcm9ubWVudElkIjoiNGVkNjQ2Y2QtYTM5OS00ZjFiLTliMTQtODY1YjhkNzhhYzhhIiwiZXhwIjoxNjg5NjIxMzExLCJpYXQiOjE2ODk2MTc3MTEsImlzcyI6ImxvYmJ5IiwibmJmIjoxNjg5NjE3NzExLCJwcm9qZWN0SWQiOiI3YzRjZDJmMC1kZmY4LTQxM2MtOTliZS0wYjY1ODExZjA2NzkiLCJyZXNvdXJjZSI6IjIzVTN0UWRYTW5ibXlkcFpaSFlrbmIiLCJzZXJ2aWNlSWQiOiJsb2JieSIsInN1YiI6InJmb1pwMDNSek9SMTJxV2FoR2Mwc0dHUHpNRDMifQ.wwMsKpDV99kor_gEStZcSxH0atzQnzd13dZeo8maUkmr2rRWIAIQGlMPfA2-UAntQ6-P8hgcfnYed5b3TG6pa4ErYUMEttGdJS5ggWhSzRxoZwujKnn6I_E6tCEd6JbfcJndajABVbXw48MwrKq4S1DEc3tK3C-zZDx8OJ17YEv0mkG0GMJk0PN6QStzf3S7VMQtSfckefo_7bes7xMOjzpOFlIlNU2PhnNOmTbwvPKnkS_JTbYNK4fR5cwga6zTV_MN-kbnj3k0G5Q5L68SXkaJtdbeNxAyYhzVWnGbNuQhHxwSpaXba0TdaUnR_rO5LSs74T2EqIa9dPRgw_6zXw","recover":false,"offset":0}}
     
  7. lsaeteurn

    lsaeteurn

    Joined:
    Jan 26, 2023
    Posts:
    93
    Looks like the same token is being used by both accounts. Since they are different identities, they should probably have different tokens.
     
  8. arnaud_gout

    arnaud_gout

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    26
    That's strange, you are using Wire 1.1.8, and at no moment you are seeing this log?

    Code (CSharp):
    1. PlayerID changed to [{ playerId }], next action: { action }
     
  9. arnaud_gout

    arnaud_gout

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    26
    And yes, if the player id changes, they should use a different token, will see on lobby sdk side and get back to you
     
  10. lsaeteurn

    lsaeteurn

    Joined:
    Jan 26, 2023
    Posts:
    93
    Not seeing that. Is there a proper way to logout? I'm currently using Anonymous login and just switching profiles. Maybe this only works with the new Unity username/password Login which I haven't got around to implementing yet.
     
  11. arnaud_gout

    arnaud_gout

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    26
    how do you switch profile?
     
  12. lsaeteurn

    lsaeteurn

    Joined:
    Jan 26, 2023
    Posts:
    93
    I call this to logout:
    AuthenticationService.Instance.SignOut();

    Then I call this to switch profiles and then login:
    var authentication = AuthenticationService.Instance;
    authentication.SwitchProfile(profileId);
    authentication.SignInAnonymouslyAsync();
     
  13. arnaud_gout

    arnaud_gout

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    26
    mhhh, that way of switching is correct should indeed trigger that log on Wire 1.1.8.
    Will look into that, but this does not explain why the tokens are identical.
    One last thing, in your snippet I don't see you awaiting the SignInAnonymously() function, so if it throws you might not see it!
    Possibly it could trigger a race condition if you are not awaiting before sending the second subscribe command.
    Basically, Wire is listening to the player id change event from the auth package to reinitialize the connection.
     
  14. lsaeteurn

    lsaeteurn

    Joined:
    Jan 26, 2023
    Posts:
    93
    That was just a copy/paste example. I am definitely awaiting it. The subscription happens at a completely different time when I actually try to join or create a lobby.
     
    arnaud_gout likes this.
  15. arnaud_gout

    arnaud_gout

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    26
    OK, just checked the tokens in jwt.io, they are actually different, with a different playerId, so that's not the problem, it's likely to be in Wire.
    Out of curiosity, could you try the SignOut but with clearCredentials = true?
     
  16. lsaeteurn

    lsaeteurn

    Joined:
    Jan 26, 2023
    Posts:
    93
    Okay, just tried it and same error. Nothing changed.
     
  17. arnaud_gout

    arnaud_gout

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    26
    thanks, I will work on a repro on my side
     
    lsaeteurn likes this.
  18. arnaud_gout

    arnaud_gout

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    26
    OK managed to have a repro with clearCredentials = false, but not with clearCredentials = true.
    Can you please double check that the clearCredentials can't work as a short term work around?
    Here is the code I used to changed identity:

    Code (CSharp):
    1. public async void ChangeIdentity()
    2. {
    3.     try
    4.     {
    5.         AuthenticationService.Instance.SignOut(false);
    6.         AuthenticationService.Instance.SwitchProfile("default" + currentProfileId % profileIdCount);
    7.         await AuthenticationService.Instance.SignInAnonymouslyAsync();
    8.         Debug.Log("UAS ID: " + AuthenticationService.Instance.PlayerId);
    9.         currentProfileId++;
    10.     }
    11.     catch (Exception e)
    12.     {
    13.         Debug.LogException(e);
    14.     }
    15. }
     
  19. lsaeteurn

    lsaeteurn

    Joined:
    Jan 26, 2023
    Posts:
    93
    It seems to be working now by setting that to true. It failed the first time when I tried it and it also failed a couple more times in my tests.

    So not 100% (probably 90%), but it's good enough for now. Could be related to the fact that the Wire connection isn't very stable (changes to Unsynced state randomly). I lose connection every 25-40 mins, but I can just simply reconnect when that happens.

    Is passing TRUE the proper way to sign out?

    Here's the code I'm using:

    Screenshot 2023-07-17 at 1.50.41 PM.jpg
     
  20. arnaud_gout

    arnaud_gout

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    26
    Yeah, sounds right.
    Right now calling authentication.SignOut(true) is a workaround for the current issue that's a bit deeper in our systems. But it is as valid as calling it with false. It's just telling Auth to not use the cached identity and renew it.
    As for the random Wire disconnection, what's expected is a disconnection every 60min, in any case, the Wire package is supposed to reconnect by itself and renew the subscriptions. You shouldn't have to do a thing, so I'm not sure what you meant by "I can just simply reconnect when that happens"?
     
  21. lsaeteurn

    lsaeteurn

    Joined:
    Jan 26, 2023
    Posts:
    93
    When the Lobby Events subscription changes to "Unsynced" and then to "Error", it doesn't auto reconnect. This happens more often than every 60 mins (25-40mins). When this happens, I lose all real time updates.

    I have to reconnect & sync with the lobby for it to work again. Not a major issue for me since I can gracefully reconnect again. With this change, I was able to run my lobby for 8 hours continuous just fine. I use the Lobby system as a Party/Squad system so it needs to stay connected beyond an hour.
     
  22. arnaud_gout

    arnaud_gout

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    26
    OK, I would love it if you had a log whenever this happens too, this is a bug I want gone ;)
     
  23. lsaeteurn

    lsaeteurn

    Joined:
    Jan 26, 2023
    Posts:
    93
    Okay, when I have some spare time, I will run it in the editor for about 30 mins.
     
  24. lsaeteurn

    lsaeteurn

    Joined:
    Jan 26, 2023
    Posts:
    93
    So it looks like signOut(true) actually deletes the anonymous accounts (or at least removes the profile locally). If that is the case, I don't want to sign out with TRUE.
     
  25. arnaud_gout

    arnaud_gout

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    26
    Got it.
    I confirm this is a bug on our side. There is a clear way of fixing this on the Wire side.
    We have a version 1.2.0 that was released yesterday.
    Will work on it and try and deliver a 1.2.1 ASAP. Stay tuned :)
     
  26. lsaeteurn

    lsaeteurn

    Joined:
    Jan 26, 2023
    Posts:
    93
    Great! I'm glad we were able to find 2 bugs.
     
  27. arnaud_gout

    arnaud_gout

    Unity Technologies

    Joined:
    Sep 17, 2021
    Posts:
    26
    Hey there, we will have to modify something in the Authentication package first in order to fix this issue.
    It might take a bit longer.
     
  28. lsaeteurn

    lsaeteurn

    Joined:
    Jan 26, 2023
    Posts:
    93
    Okay, no problem.