fix: shutdown and shutdown notification issues [MTT-7791] [MTT-7540]#2789
Conversation
…upon-host-server-shutdown
When a client disconnects itself or is disconnected by the server, it now returns its client identifier. Server or host shutdown sequence now includes a "soft shutdown" where the server-host will send out disconnection messages to all clients with the reason for the client being disconnected.
fixing exceptions when certain missing properties are not set (primarily buttons or toggles)
| } | ||
| } | ||
| else | ||
| if (!NetworkManager.ShutdownInProgress) |
There was a problem hiding this comment.
Any particular reason you're putting all these ifs on their own line instead of using the standard else if?
There was a problem hiding this comment.
It is the standard way to do that, but can make it all one line.
There was a problem hiding this comment.
I am mistaken... I have Rust in my brain.
"else if" is the correct way (my brain went on vacation Wednesday night)
| ConnectedClients.Clear(); | ||
| ConnectedClientIds.Clear(); | ||
| ConnectedClientsList.Clear(); | ||
|
|
There was a problem hiding this comment.
Not a critique, just curious why these (and ProcessSendQueues) needed to be moved, just so I can understand the changes you made better.
There was a problem hiding this comment.
Ahh... yeah this is because the DisconnectRemoteClient(clientId) invocation below on line 1132 can invoke OnClientDisconnectFromServer which invokes DisconnectRemoteClient:
internal void DisconnectRemoteClient(ulong clientId)
{
MessageManager.ProcessSendQueues();
OnClientDisconnectFromServer(clientId);
}
It processes the send queue prior to invoking OnClientDisconnectFromServer(clientId);. However, on line 995 (within OnClientDisconnectFromServer) the ClientDisconnectedMessage is being sent to any remaining connected clients. This means the last client to be disconnected would not get the ClientDisconnectedMessage if a host or server was shutting down.
I didn't want to change the order of operations in DisconnectRemoteClient but wanted to make sure the last ClientDisconnectedMessage was sent out.
(it is sort of a mute point...but I guess I was just in the "make sure any last messages are sent" mode)
Thinking about it... the last client would get the last message... so I probably don't need to do that... and since I am sending disconnect messages prior to even shutting down... that probably doesn't even need to be invoked any longer.
| { | ||
| if (m_NetworkBehaviour.NetworkManager.LogLevel <= LogLevel.Developer) | ||
| { | ||
| Debug.LogWarning($"NetworkVariable is written to during the NetworkManager shutdown! " + |
There was a problem hiding this comment.
The wording of this message feels a little passive aggressive to me. "Are you doing X? If so, try not to do X." I feel like the second sentence is implied by the question and can be left off.
…er-shutdown' of https://github.com/Unity-Technologies/com.unity.netcode.gameobjects into fix/client-owned-objects-cause-exception-upon-host-server-shutdown
…upon-host-server-shutdown
This PR includes several fixes to the NetworkManager shutdown sequence where:
MTT-7791
MTT-7540
fix: #2759
fix: #2705
fix: #2699
fix: #2389
fix: #2064
fix: #1880
Changelog
OnClientDisconnectedCallbackwas not being invoked under certain conditions.OnClientDisconnectedCallbackwas always returning 0 as the client identifier.NetworkVariableorNetworkListwithinOnNetworkDespawnduring a shutdown sequence would throw an exception.NetworkManager.Shutdownis invoked. This will send a disconnect notification to all connected clients and the server-host will wait for all connected clients to disconnect or timeout after a 5 second period before completing the shutdown process.OnClientDisconnectedCallbackwill now return the assigned client identifier on the local client side if the client was approved and assigned one prior to being disconnected.Testing and Documentation