Skip to content

Commit e3ace4e

Browse files
fix: Clear adapter send queues on client disconnection (#1649)
* fix: Clear adapter send queues on client disconnection * Add PR number to CHANGELOG entry * fix accept both in merge blasted a }. This fixes that. Co-authored-by: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Co-authored-by: Noel Stephens <noel.stephens@unity3d.com>
1 parent f47ed35 commit e3ace4e

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

com.unity.netcode.adapter.utp/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ All notable changes to this package will be documented in this file. The format
1010

1111
### Fixed
1212

13+
- Fixed issue where disconnecting from the server with data still in the queue would result in an error message about a stale connection. (#1649)
1314
- Fixed issue where the server `NetworkEndPoint` would fail to be created when 'Server Listen Address' is empty. (#1636)
1415
- Fixed issue with native collections not all being disposed of when destroying the component without shutting it down properly. This would result in errors in the console and memory leaks. (#1640)
1516
- Fixed an issue where packets causing errors would not be removed from the send queue, which would cause the error message to be spammed on every frame as the adapter would try to resend the packet. (#1648)

com.unity.netcode.adapter.utp/Tests/Runtime/ConnectionTests.cs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using NUnit.Framework;
2+
using System;
23
using System.Collections;
34
using System.Collections.Generic;
45
using System.Linq;
@@ -23,15 +24,15 @@ public IEnumerator Cleanup()
2324
if (m_Server)
2425
{
2526
m_Server.Shutdown();
26-
Object.DestroyImmediate(m_Server);
27+
UnityEngine.Object.DestroyImmediate(m_Server);
2728
}
2829

2930
foreach (var transport in m_Clients)
3031
{
3132
if (transport)
3233
{
3334
transport.Shutdown();
34-
Object.DestroyImmediate(transport);
35+
UnityEngine.Object.DestroyImmediate(transport);
3536
}
3637
}
3738

@@ -283,6 +284,46 @@ public IEnumerator DifferentServerAndListenAddresses()
283284
yield return null;
284285
}
285286

287+
// Check server disconnection with data in send queue.
288+
[UnityTest]
289+
public IEnumerator ServerDisconnectWithDataInQueue()
290+
{
291+
InitializeTransport(out m_Server, out m_ServerEvents);
292+
InitializeTransport(out m_Clients[0], out m_ClientsEvents[0]);
293+
294+
m_Server.StartServer();
295+
m_Clients[0].StartClient();
296+
297+
yield return WaitForNetworkEvent(NetworkEvent.Connect, m_ServerEvents);
298+
299+
var data = new ArraySegment<byte>(new byte[] { 42 });
300+
m_Server.Send(m_ServerEvents[0].ClientID, data, NetworkDelivery.Unreliable);
301+
302+
m_Server.DisconnectRemoteClient(m_ServerEvents[0].ClientID);
303+
304+
yield return WaitForNetworkEvent(NetworkEvent.Disconnect, m_ClientsEvents[0]);
305+
}
306+
307+
// Check client disconnection with data in send queue.
308+
[UnityTest]
309+
public IEnumerator ClientDisconnectWithDataInQueue()
310+
{
311+
InitializeTransport(out m_Server, out m_ServerEvents);
312+
InitializeTransport(out m_Clients[0], out m_ClientsEvents[0]);
313+
314+
m_Server.StartServer();
315+
m_Clients[0].StartClient();
316+
317+
yield return WaitForNetworkEvent(NetworkEvent.Connect, m_ServerEvents);
318+
319+
var data = new ArraySegment<byte>(new byte[] { 42 });
320+
m_Clients[0].Send(m_Clients[0].ServerClientId, data, NetworkDelivery.Unreliable);
321+
322+
m_Clients[0].DisconnectLocalClient();
323+
324+
yield return WaitForNetworkEvent(NetworkEvent.Disconnect, m_ServerEvents);
325+
}
326+
286327
// Check that a server can disconnect a client after another client has disconnected.
287328
[UnityTest]
288329
public IEnumerator ServerDisconnectAfterClientDisconnect()

0 commit comments

Comments
 (0)