Skip to content

fix: client throws a not server exception when destroying a NetworkObject while shutting down [MTT-6210] #2510

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

Merged

Conversation

NoelStephensUnity
Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity commented Apr 13, 2023

This fixes the edge case scenarios where a client could abruptly shutdown (host drops connection or the like) while NetworkObjects are still spawned. Under these conditions, the client-side would throw an exception if it was in the middle of the shutdown process which would disrupt the shutdown sequence.

This includes a minor modification to the NetworkLog server logging where a client generating any type of server log would get the standard [Netcode] message header/prefix and on the server-side it would generate the typical [Netcode-Server Sender=#] header/prefix. It additionally provides a means to test and validate server NetworkLog messages.

MTT-6210
Pertains to #2480

Changelog

  • Fixed: issue where a client could throw an exception if abruptly disconnected from a network session with one or more spawned NetworkObject(s).

Testing and Documentation

  • Includes integration test updates to NetworkObjectDestroyTests.TestNetworkObjectClientDestroy.
  • No documentation changes or additions were necessary.

This resolves some edge case scenarios where a client could be shutting down with spawned NetworkObjects but would throw an exception under this valid scenario which would disrupt the shutdown sequence on the client side.
Changing the NetworkLog.LogError to NetworkLog.LogErrorServer.
Minor modification to NetworkLog.LogServer to provide testing for server log messages and to provide standard message header prefix on the client-side (i.e [Netcode]).
Updating NetworkObjectDestroyTests.TestNetworkObjectClientDestroy to test both when a client destroys a NetworkObject (making sure the server-side receives the error message as well) and when a client destroys a spawned NetworkObject while shutting down.
@NoelStephensUnity NoelStephensUnity requested a review from a team as a code owner April 13, 2023 23:14
updating the changelog
Making the NetworkLog message generate when the log level is error or lower and updating comments.
last comment adjustment
updating some style based issues
Adjusted the way we detect the test to use a more conditional wait approach for slower systems.
Updated TrackServerLogSentMetric to detect the message sent.
Added HasLogBeenReceived method to NetcodeLogAssert in order to be able to just wait for the console log (for slower systems).
@NoelStephensUnity NoelStephensUnity requested a review from a team as a code owner April 14, 2023 01:30
breaking from the regex version of NetcodeLogAsseert.LogWasReceived so it doesn't continue to parse through the log after it found the match it was looking for.
public bool HasLogBeenReceived(LogType type, string message)
{
var found = false;
lock (m_Lock)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit scared to see lock in the codebase, what's going on here?

@@ -51,35 +51,58 @@ public static class NetworkLog
/// <param name="message">The message to log</param>
public static void LogErrorServer(string message) => LogServer(message, LogType.Error);

internal static NetworkManager NetworkManagerOverride;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this strictly for tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is indeed. Since it was always using the singleton, up until this we have never fully tested server network logs generated clients.

Comment on lines -62 to +92
LogInfoServerLocal(message, localId);
if (isServer)
{
LogInfoServerLocal(message, localId);
}
else
{
LogInfo(message);
}
break;
case LogType.Warning:
LogWarningServerLocal(message, localId);
if (isServer)
{
LogWarningServerLocal(message, localId);
}
else
{
LogWarning(message);
}
break;
case LogType.Error:
LogErrorServerLocal(message, localId);
if (isServer)
{
LogErrorServerLocal(message, localId);
}
else
{
LogError(message);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if these changes are necessary

(IsSceneObject == null || (IsSceneObject.Value != true)))
{
throw new NotServerException($"Destroy a spawned {nameof(NetworkObject)} on a non-host client is not valid. Call {nameof(Destroy)} or {nameof(Despawn)} on the server/host instead.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this just simply be replaced with an error log without changing things around it too much?
if we're only trying to error-and-continue instead of exception-throw to keep the shutdown sequence running, let's "just" do that and nothing else as the minimal fix?

Copy link
Contributor

@0xFA11 0xFA11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could only convert throw new NotServerException into a Debug.LogError or NetworkLog.LogError as a minimal fix without touching anything else.

@0xFA11 0xFA11 merged commit 2717686 into develop Apr 15, 2023
@0xFA11 0xFA11 deleted the fix/client-exception-not-server-destroying-networkobject branch April 15, 2023 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants