Skip to content

fix: Don't let exceptions in OnNetworkSpawn/OnNetworkDespawn block processing of the next callback. [MTT-1378] #1739

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
merged 17 commits into from
Aug 25, 2022

Conversation

ShadauxCat
Copy link
Collaborator

@ShadauxCat ShadauxCat commented Feb 22, 2022

MTT-1378

Changelog

com.unity.netcode.gameobjects

  • Fixed: Fixed throwing an exception in OnNetworkUpdate causing other OnNetworkUpdate calls to not be executed.

Testing and Documentation

  • Includes integration tests.
  • No documentation changes or additions were necessary.

Copy link
Contributor

@mattwalsh-unity mattwalsh-unity left a comment

Choose a reason for hiding this comment

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

Want to understand more about the absorbing of exceptions

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.

+1 for Debug.LogException() instead of NetworkLog.LogError() both in spawn and despawn flows.
also LogAssert.Expect exists, that'd potentially make tests simpler too.

@TwoTenPvP
Copy link
Contributor

+1 for Debug.LogException() instead of NetworkLog.LogError() both in spawn and despawn flows.

also LogAssert.Expect exists, that'd potentially make tests simpler too.

Surley we want to use NetworkLog though? Perhaps adding NetworkLog.LogException

Otherwise NetworkLog is incomplete if only half the logs are networked.

@0xFA11
Copy link
Contributor

0xFA11 commented Mar 22, 2022

+1 for Debug.LogException() instead of NetworkLog.LogError() both in spawn and despawn flows.
also LogAssert.Expect exists, that'd potentially make tests simpler too.

Surley we want to use NetworkLog though? Perhaps adding NetworkLog.LogException

Otherwise NetworkLog is incomplete if only half the logs are networked.

I see your point @TwoTenPvP but I think NetworkLog & NetworkLog.LogException needs a separate conversation. We might come back to this to update once we have that other discussion.

@TwoTenPvP
Copy link
Contributor

+1 for Debug.LogException() instead of NetworkLog.LogError() both in spawn and despawn flows.

also LogAssert.Expect exists, that'd potentially make tests simpler too.

Surley we want to use NetworkLog though? Perhaps adding NetworkLog.LogException

Otherwise NetworkLog is incomplete if only half the logs are networked.

I see your point @TwoTenPvP but I think NetworkLog & NetworkLog.LogException needs a separate conversation. We might come back to this to update once we have that other discussion.

Personally I prefer a bit worse log messages than an incomplete feature. NetworkLog.LogError / Debug.LogException.

I think using NetworkLog.LogError is the best choice if NetworkLog.LogException is out of the question

Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity left a comment

Choose a reason for hiding this comment

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

Looks perfectly fine to me!
(except the integration test)

🙈

@JesseOlmer JesseOlmer changed the title fix: Don't let exceptions in OnNetworkSpawn/OnNetworkDespawn block processing of the next callback. fix: Don't let exceptions in OnNetworkSpawn/OnNetworkDespawn block processing of the next callback. [MTT-1378] May 5, 2022
@JesseOlmer JesseOlmer closed this May 5, 2022
@JesseOlmer JesseOlmer reopened this May 5, 2022
@JesseOlmer
Copy link
Contributor

Closed and re-opened to fix the JIRA association. Please make sure to add the JIRA ticket to the title upon PR creation in the future.

# Conflicts:
#	com.unity.netcode.gameobjects/CHANGELOG.md
#	com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs
@ShadauxCat ShadauxCat requested a review from a team as a code owner May 9, 2022 21:56
private GameObject[] m_Objects = new GameObject[5];

[UnityTest]
public IEnumerator WhenOnNetworkSpawnThrowsException_FutureOnNetworkSpawnsAreNotPrevented()
Copy link
Contributor

Choose a reason for hiding this comment

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

These tests feel pretty rough in their current state.

  • There are lots of magic numbers. There are even magic numbers that depend on other magic numbers (2, 3, and 5)
  • You have 1 setup for 2 different tests. Is all the code in the setup necessary for both?
  • You have log asserts in your test setup. Are these asserts actual tests, or are they an attempt to verify that setup has done what it's expected to?
  • You are using the multi-instance tests and have a client but it's unclear if this is actually necessary for this test (don't these virtual methods get invoked on the server too? Can't you write a much simpler/more contained UnityTest that doesn't involve a client or waiting for frames with timeout asserts and if (IsClient)?)
  • It's unclear (to me) why you have if (NumClientSpawns > 2) guard in the test components.

While it's a very contentious topic, generally speaking, the more self-contained a test is, the better for understanding and lower the risk for future false positives. I'm not personally a fan of having to read 3 classes and 6 methods to understand what's actually happening in this 1 line test case.

Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity May 23, 2022

Choose a reason for hiding this comment

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

While throwing an exception in a component added to the player prefab is valid, I think this test should add more NetworkBehaviour derived components because the real test is to validate that all NetworkBehaviour components on a GameObject get OnNetworkSpawn and OnNetworkDespawn invoked even if one of the components throws and exception.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I've addressed everything you mentioned here, except for the use of multi-instance tests. I think it's valuable to test that the behavior is the same on both server and client. I did, however, update the test to make sure it isn't exclusively a client-side test, since OnNetworkSpawn and OnNetworkDespawn are called on the server too.

@NoelStephensUnity NoelStephensUnity self-requested a review May 23, 2022 23:05
Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity left a comment

Choose a reason for hiding this comment

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

The included integration test only verifies that it throws an exception but does not verify that other components on the same GameObject still have their OnNetworkSpawn and OnNetworkDespawn method invoked when there are one or more NetworkBehaviour components on the GameObject and one of them throws an exception during the spawn/despawn periods.

Maybe adding an additional component after the one that throws an exception could be the verification that it was invoked after the NetworkBehaviour before it throws an exception?

ShadauxCat and others added 5 commits August 24, 2022 10:54
# Conflicts:
#	com.unity.netcode.gameobjects/CHANGELOG.md
Also fixed merge issue with changelog.
# Conflicts:
#	com.unity.netcode.gameobjects/CHANGELOG.md
#	com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs
fixing white space issue.
Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity left a comment

Choose a reason for hiding this comment

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

Looks good to me kitty!

@NoelStephensUnity NoelStephensUnity enabled auto-merge (squash) August 24, 2022 23:41
@NoelStephensUnity NoelStephensUnity merged commit 244d8d3 into develop Aug 25, 2022
@NoelStephensUnity NoelStephensUnity deleted the fix/catch_exceptions_in_OnNetworkSpawn branch August 25, 2022 00:18
jakobbbb pushed a commit to GooseGirlGames/com.unity.netcode.gameobjects that referenced this pull request Feb 22, 2023
…ocessing of the next callback. [MTT-1378] (Unity-Technologies#1739)

* fix: Don't let exceptions in OnNetworkSpawn/OnNetworkDespawn block processing of the next callback.

* Standards and changelog.

* Standards fixes

* It would be good to check in the right file.

* I swear these tests passed before but I have no idea how.

Also review feedback.

* Address review feedback.

* Switched to LogAssert.Expect

* Updated tests to NetcodeIntegrationTest style

* Standards fix

* Rewrote tests according to feedback.

Also fixed merge issue with changelog.

* Test the behavior on both server and client

* style

fixing white space issue.

* Update com.unity.netcode.gameobjects/CHANGELOG.md

Co-authored-by: Fatih Mar <[email protected]>

Co-authored-by: Noel Stephens <[email protected]>
Co-authored-by: Fatih Mar <[email protected]>
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.

6 participants