From d94995e4e0477a8f79bc47822b8202e5f1d0896f Mon Sep 17 00:00:00 2001 From: Forest Date: Tue, 30 Mar 2021 00:21:53 -0700 Subject: [PATCH] Fix a very strange issue around the socket on message read callback potentially being called twice --- Hazel/Udp/UnityUdpClientConnection.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Hazel/Udp/UnityUdpClientConnection.cs b/Hazel/Udp/UnityUdpClientConnection.cs index 422b28e..81d6d1b 100644 --- a/Hazel/Udp/UnityUdpClientConnection.cs +++ b/Hazel/Udp/UnityUdpClientConnection.cs @@ -229,6 +229,13 @@ namespace Hazel.Udp DisconnectInternal(HazelInternalErrors.SocketExceptionReceive, "Socket exception while reading data: " + e.Message); return; } + catch (ObjectDisposedException) + { + // Weirdly, it seems that this method can be called twice on the same AsyncState when object is disposed... + // So this just keeps us from hitting Duplicate Add errors at the risk of if this is a platform + // specific bug, we leak a MessageReader while the socket is disposing. Not a bad trade off. + return; + } catch (Exception) { msg.Recycle(); -- 2.39.5