From 1429dd2e31c2e8b5db75254c16480034eca30fd3 Mon Sep 17 00:00:00 2001 From: Chris Danek Date: Tue, 22 Nov 2022 05:20:27 -0800 Subject: [PATCH 1/2] Update Server.cs Removed chained calls from GetClientAddress() to help diagnose rare NRE. --- Telepathy/Server.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Telepathy/Server.cs b/Telepathy/Server.cs index 0b4ada7..0e575f4 100644 --- a/Telepathy/Server.cs +++ b/Telepathy/Server.cs @@ -321,7 +321,11 @@ public string GetClientAddress(int connectionId) // find the connection if (clients.TryGetValue(connectionId, out ConnectionState connection)) { - return ((IPEndPoint)connection.client.Client.RemoteEndPoint).Address.ToString(); + TcpClient tcpClient = connection.client; + Socket clientSocket = tcpClient.Client; + IPEndPoint clientEndpoint = (IPEndPoint)clientSocket.RemoteEndPoint; + IPAddress ipAddress = clientEndpoint.Address; + return ipAddress.ToString(); } return ""; } From 3e3fb988317ed21173bf16a3e42f02b140063a3b Mon Sep 17 00:00:00 2001 From: Chris Danek Date: Sat, 7 Jan 2023 21:10:47 -0800 Subject: [PATCH 2/2] Add NRE resiliency to Server.GetClientAddress() --- Telepathy/Server.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Telepathy/Server.cs b/Telepathy/Server.cs index 0e575f4..da12e1c 100644 --- a/Telepathy/Server.cs +++ b/Telepathy/Server.cs @@ -322,9 +322,13 @@ public string GetClientAddress(int connectionId) if (clients.TryGetValue(connectionId, out ConnectionState connection)) { TcpClient tcpClient = connection.client; + if (tcpClient == null) return ""; Socket clientSocket = tcpClient.Client; + if (clientSocket == null) return ""; IPEndPoint clientEndpoint = (IPEndPoint)clientSocket.RemoteEndPoint; + if (clientEndpoint == null) return ""; IPAddress ipAddress = clientEndpoint.Address; + if (ipAddress == null) return ""; return ipAddress.ToString(); } return "";