-
Notifications
You must be signed in to change notification settings - Fork 456
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
fix: client throws a not server exception when destroying a NetworkObject while shutting down [MTT-6210] #2510
Conversation
Making the NetworkLog message generate when the log level is error or lower and updating comments.
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).
public bool HasLogBeenReceived(LogType type, string message) | ||
{ | ||
var found = false; | ||
lock (m_Lock) |
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'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; |
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.
is this strictly for tests?
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 indeed. Since it was always using the singleton, up until this we have never fully tested server network logs generated clients.
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); | ||
} |
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'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."); |
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.
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?
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 think we could only convert throw new NotServerException
into a Debug.LogError
or NetworkLog.LogError
as a minimal fix without touching anything else.
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
NetworkObject
(s).Testing and Documentation