Skip to content

fix: Make NetworkManager.Shutdown idempotent #1877

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 4 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ Additional documentation and release notes are available at [Multiplayer Documen
- Fixed issue during client synchronization if 'ValidateSceneBeforeLoading' returned false it would halt the client synchronization process resulting in a client that was approved but not synchronized or fully connected with the server. (#1883)
- Fixed an issue where UNetTransport.StartServer would return success even if the underlying transport failed to start (#854)

## [Unreleased]

### Removed
- Removed `SIPTransport` (#1870)
Comment on lines +25 to +26
Copy link
Contributor Author

@simon-lemay-unity simon-lemay-unity Apr 14, 2022

Choose a reason for hiding this comment

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

Note that this entry had been accidently put under the 1.0.0-pre.7 section.


### Fixed
- Fixed an issue where calling `Shutdown` on a `NetworkManager` that was already shut down would cause an immediate shutdown the next time it was started (basically the fix makes `Shutdown` idempotent). (#1877)

## [1.0.0-pre.7] - 2022-04-06

### Added
Expand All @@ -38,7 +46,6 @@ Additional documentation and release notes are available at [Multiplayer Documen

### Removed

- Removed `SIPTransport` (#1870)
- Removed `SnapshotSystem` (#1852)
- Removed `com.unity.modules.animation`, `com.unity.modules.physics` and `com.unity.modules.physics2d` dependencies from the package (#1812)
- Removed `com.unity.collections` dependency from the package (#1849)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1167,8 +1167,13 @@ public void Shutdown(bool discardMessageQueue = false)
NetworkLog.LogInfo(nameof(Shutdown));
}

m_ShuttingDown = true;
m_StopProcessingMessages = discardMessageQueue;
// If we're not running, don't start shutting down, it would only cause an immediate
// shutdown the next time the manager is started.
if (IsServer || IsClient)
{
m_ShuttingDown = true;
m_StopProcessingMessages = discardMessageQueue;
}
}

internal void ShutdownInternal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,37 @@ public IEnumerator WhenShuttingDownAndRestarting_SDKRestartsSuccessfullyAndStays
Assert.IsTrue(m_ServerNetworkManager.IsServer);
Assert.IsTrue(m_ServerNetworkManager.IsListening);
}

[UnityTest]
public IEnumerator WhenShuttingDownTwiceAndRestarting_SDKRestartsSuccessfullyAndStaysRunning()
{
// shutdown the server
m_ServerNetworkManager.Shutdown();

// wait 1 frame because shutdowns are delayed
var nextFrameNumber = Time.frameCount + 1;
yield return new WaitUntil(() => Time.frameCount >= nextFrameNumber);

// Verify the shutdown occurred
Assert.IsFalse(m_ServerNetworkManager.IsServer);
Assert.IsFalse(m_ServerNetworkManager.IsListening);
Assert.IsFalse(m_ServerNetworkManager.IsHost);
Assert.IsFalse(m_ServerNetworkManager.IsClient);

// Shutdown the server again.
m_ServerNetworkManager.Shutdown();

m_ServerNetworkManager.StartServer();
// Verify the server started
Assert.IsTrue(m_ServerNetworkManager.IsServer);
Assert.IsTrue(m_ServerNetworkManager.IsListening);

// Wait several frames / one full network tick
yield return s_DefaultWaitForTick;

// Verify the server is still running
Assert.IsTrue(m_ServerNetworkManager.IsServer);
Assert.IsTrue(m_ServerNetworkManager.IsListening);
}
}
}