Skip to content

Commit d70dcbb

Browse files
fix: Infinite NetworkManager.ShutdownInternal on NetworkTransport.DisconnectLocalClient Exception [MTT-5551] (#2433)
* fix Prevent an infinite shutdown sequence from happening if NetworkTransport.DisconnectLocalClient throws an exception during NetworkManager.ShutdownInternal. If UnityTransport.FlushSendQueuesForClientId throws an exception, log the exception and allow the invoking method to continue processing.
1 parent ecdd64e commit d70dcbb

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,10 +1197,22 @@ internal void ShutdownInternal()
11971197
}
11981198
}
11991199

1200+
// Unregister network updates before trying to disconnect the client
1201+
this.UnregisterAllNetworkUpdates();
1202+
12001203
if (IsClient && IsListening)
12011204
{
12021205
// Client only, send disconnect to server
1203-
NetworkConfig.NetworkTransport.DisconnectLocalClient();
1206+
// If transport throws and exception, log the exception and
1207+
// continue the shutdown sequence (or forever be shutting down)
1208+
try
1209+
{
1210+
NetworkConfig.NetworkTransport.DisconnectLocalClient();
1211+
}
1212+
catch (Exception ex)
1213+
{
1214+
Debug.LogException(ex);
1215+
}
12041216
}
12051217

12061218
IsConnectedClient = false;
@@ -1221,8 +1233,6 @@ internal void ShutdownInternal()
12211233
IsServer = false;
12221234
IsClient = false;
12231235

1224-
this.UnregisterAllNetworkUpdates();
1225-
12261236
if (NetworkTickSystem != null)
12271237
{
12281238
NetworkTickSystem.Tick -= OnNetworkManagerTick;

com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,10 @@ public void Execute()
763763
// Send as many batched messages from the queue as possible.
764764
private void SendBatchedMessages(SendTarget sendTarget, BatchedSendQueue queue)
765765
{
766+
if (!m_Driver.IsCreated)
767+
{
768+
return;
769+
}
766770
new SendBatchedMessagesJob
767771
{
768772
Driver = m_Driver.ToConcurrent(),

0 commit comments

Comments
 (0)