-
Notifications
You must be signed in to change notification settings - Fork 438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: shutdown and shutdown notification issues [MTT-7791] [MTT-7540] #2789
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)
com.unity.netcode.gameobjects/Runtime/Connection/NetworkConnectionManager.cs
Show resolved
Hide resolved
@@ -925,6 +935,7 @@ internal void OnClientDisconnectFromServer(ulong clientId) | |||
} | |||
} | |||
else | |||
if (!NetworkManager.ShutdownInProgress) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the standard way to do that, but can make it all one line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
OnClientDisconnectedCallback
was not being invoked under certain conditions.OnClientDisconnectedCallback
was always returning 0 as the client identifier.NetworkVariable
orNetworkList
withinOnNetworkDespawn
during a shutdown sequence would throw an exception.NetworkManager.Shutdown
is 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.OnClientDisconnectedCallback
will 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