Skip to content

fix: Prevent an exception in UTP when host disconnects #1441

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 1 commit into from
Nov 23, 2021
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 packet overflow errors when sending payloads too close to the MTU (was mostly visible when using Relay).
- Don't throw an exception when the host disconnects (issue 1439 on GitHub).

## [1.0.0-pre.3] - 2021-10-22

Expand Down
14 changes: 8 additions & 6 deletions com.unity.netcode.adapter.utp/Runtime/UnityTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -435,20 +435,22 @@ private bool ProcessEvent()
}
case TransportNetworkEvent.Type.Disconnect:
{
InvokeOnTransportEvent(NetcodeNetworkEvent.Disconnect,
ParseClientId(networkConnection),
default(ArraySegment<byte>),
Time.realtimeSinceStartup);

if (m_ServerConnection.IsCreated)
{
m_ServerConnection = default;
if (m_Driver.GetConnectionState(m_ServerConnection) == NetworkConnection.State.Connecting)

var reason = reader.ReadByte();
if (reason == (byte)Networking.Transport.Error.DisconnectReason.MaxConnectionAttempts)
{
Debug.LogError("Client failed to connect to server");
}
}

InvokeOnTransportEvent(NetcodeNetworkEvent.Disconnect,
ParseClientId(networkConnection),
default(ArraySegment<byte>),
Time.realtimeSinceStartup);

m_State = State.Disconnected;
return true;
}
Expand Down