Overridden `OnServerAddPlayer` causes "no more players for this connection" error on return to lobby

We have a Lobby scene, and a Game scene, and the usual flow of start → lobby → game works perfectly. We would like to be able to abort the current game and return to the lobby, but this currently doesn’t work.

When we call NetworkLobbyManager.ServerReturnToLobby() on the server, it correctly loads the relevant scenes, but then the program breaks because there is already a player on the given connection. Specifically:

  • NetworkLobbyManager.OnClientSceneChanged is called

  • That calls OnServerAddPlayer somehow (can’t see how, but it does)

  • That calls our specialised OnServerAddPlayer, which calls up to base.OnServerAddPlayer

  • This function sees that there is already a player on the connection, and bails out

Has anyone else successfully overridden OnServerAddPlayer and been able to use ServerReturnToLobby without problems? Is there something specific that needs to be done to remove or replace a player from the connection when returning to the lobby?

It’s possible that my problem is related to this 2.5 year old bug: Unity Issue Tracker - NetworkLobbyPlayer not removed when client disconnects
But it’s also possible that it’s a fault on our side.