Skip to content

fix: Clear adapter send queues on client disconnection #1649

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 7 commits into from
Feb 10, 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
1 change: 1 addition & 0 deletions com.unity.netcode.adapter.utp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to this package will be documented in this file. The format

### Fixed

- Fixed issue where disconnecting from the server with data still in the queue would result in an error message about a stale connection. (#1649)
- Fixed issue where the server `NetworkEndPoint` would fail to be created when 'Server Listen Address' is empty. (#1636)
- 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)
- 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)
Expand Down
45 changes: 43 additions & 2 deletions com.unity.netcode.adapter.utp/Tests/Runtime/ConnectionTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -23,15 +24,15 @@ public IEnumerator Cleanup()
if (m_Server)
{
m_Server.Shutdown();
Object.DestroyImmediate(m_Server);
UnityEngine.Object.DestroyImmediate(m_Server);
}

foreach (var transport in m_Clients)
{
if (transport)
{
transport.Shutdown();
Object.DestroyImmediate(transport);
UnityEngine.Object.DestroyImmediate(transport);
}
}

Expand Down Expand Up @@ -283,6 +284,46 @@ public IEnumerator DifferentServerAndListenAddresses()
yield return null;
}

// Check server disconnection with data in send queue.
[UnityTest]
public IEnumerator ServerDisconnectWithDataInQueue()
{
InitializeTransport(out m_Server, out m_ServerEvents);
InitializeTransport(out m_Clients[0], out m_ClientsEvents[0]);

m_Server.StartServer();
m_Clients[0].StartClient();

yield return WaitForNetworkEvent(NetworkEvent.Connect, m_ServerEvents);

var data = new ArraySegment<byte>(new byte[] { 42 });
m_Server.Send(m_ServerEvents[0].ClientID, data, NetworkDelivery.Unreliable);

m_Server.DisconnectRemoteClient(m_ServerEvents[0].ClientID);

yield return WaitForNetworkEvent(NetworkEvent.Disconnect, m_ClientsEvents[0]);
}

// Check client disconnection with data in send queue.
[UnityTest]
public IEnumerator ClientDisconnectWithDataInQueue()
{
InitializeTransport(out m_Server, out m_ServerEvents);
InitializeTransport(out m_Clients[0], out m_ClientsEvents[0]);

m_Server.StartServer();
m_Clients[0].StartClient();

yield return WaitForNetworkEvent(NetworkEvent.Connect, m_ServerEvents);

var data = new ArraySegment<byte>(new byte[] { 42 });
m_Clients[0].Send(m_Clients[0].ServerClientId, data, NetworkDelivery.Unreliable);

m_Clients[0].DisconnectLocalClient();

yield return WaitForNetworkEvent(NetworkEvent.Disconnect, m_ServerEvents);
}

// Check that a server can disconnect a client after another client has disconnected.
[UnityTest]
public IEnumerator ServerDisconnectAfterClientDisconnect()
Expand Down