Error when quitting game in editor with leaving session

When I am testing my multiplayer game in the editor using the new multiplayer SDK with NGO, whenever I normally leave a session, I have a callback for NGO ClientStopped where I remove the player from the session, so that it will not leave an empty session in the sessions list.

   private async void ClientStopped(bool host)
    {
        if (session != null)
        {
            await session.LeaveAsync();
            session = null;
        }
    }

This works in the normal build, but when I’m in the editor, if I try quitting while connected by clicking the stop button in the editor, it will give this error:

ObjectDisposedException: Cannot access a disposed object.
Object name: '$lobby!!!pbenVaYbwj657a8Gxyu8na!!!b60226d4-5d39-4f13-8379-2b254a35f88b!!!cf0992d2-36e3-44bd-a060-8492a9cc4aaa'.
Unity.Services.Wire.Internal.Subscription.UnsubscribeAsync () (at ./Library/PackageCache/com.unity.services.wire@098672f918fa/Runtime/Centrifuge/Subscription.cs:196)
Unity.Services.Lobbies.Internal.LobbyChannel.UnsubscribeAsync () (at ./Library/PackageCache/com.unity.services.multiplayer@e7b9f7939c7c/Runtime/Lobbies/SDK/LobbyUpdates/Internal/LobbyChannel.cs:70)
Unity.Services.Multiplayer.LobbyHandler.LobbyUnsubscribeCallbacksAsync () (at ./Library/PackageCache/com.unity.services.multiplayer@e7b9f7939c7c/Runtime/Multiplayer/Lobby/LobbyHandler.cs:238)
Unity.Services.Multiplayer.LobbyHandler.ResetAsync () (at ./Library/PackageCache/com.unity.services.multiplayer@e7b9f7939c7c/Runtime/Multiplayer/Lobby/LobbyHandler.cs:774)
Unity.Services.Multiplayer.SessionHandler.LeaveAsync () (at ./Library/PackageCache/com.unity.services.multiplayer@e7b9f7939c7c/Runtime/Multiplayer/Session/SessionHandler.cs:593)
CustomNetworkManager.ClientStopped (System.Boolean host) (at Assets/Scripts/Infrastructure/CustomNetworkManager.cs:136)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) (at <191a1970a53948f9819ac1d2e4f5c72e>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <84f0d810adef4e6c8deab33e4ae93f7c>:0)
UnityEngine.UnitySynchronizationContext.Exec () (at <84f0d810adef4e6c8deab33e4ae93f7c>:0)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at <84f0d810adef4e6c8deab33e4ae93f7c>:0)

You’re awaiting a task during shutdown. This can be problematic because there’s no guarantee that the awaited Task will correctly work during shutdown or completes in time to return to ClientStopped. Unity doesn’t strictly “await” for your awaited tasks when it is shutting down.

You can respond to OnApplicationQuit and flag that you’re shutting down and either perform the task synchronously if possible or just skip it if possible.

If you have to perform async tasks on shutdown, you can hook into wantsToQuit and I believe there’s a way to suppress the shutdown, or at least delay it until after your async tasks complete. Try researching in that direction.

This only happens in the editor though. When I run an actual build of the game and quit the game fully, I see no errors in the logs. In fact, this logic for leaving the session actually comes from when I was still working with lobbies before they deprecated it, and everything worked fine there if I tried to leave play mode in the editor. This task is not only supposed to be run on shutdown, this is only supposed to be run when the client gets stopped, either they are leaving the session and going back to the main menu or just fully exiting the game, which is why I am using this ClientStopped event.