From 7925caf1a2df1399e77875266343beba9b588013 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Tue, 7 Apr 2026 21:19:33 +0000 Subject: [PATCH] catch boost tcp's remote_endpoint() throwing and crashing the server this happens when, somehow, the client disconnects before we get here. I had this happen when breaking in the debugger and continuing, which leads to clients timing out (client-side timeouts). --- src/TNetwork.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index accc8c6..b76829a 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -661,15 +661,19 @@ void TNetwork::DisconnectClient(const std::weak_ptr &c, const std::stri void TNetwork::DisconnectClient(TClient &c, const std::string &R) { if (c.IsDisconnected()) return; - std::string ClientIP = c.GetTCPSock().remote_endpoint().address().to_string(); - mClientMapMutex.lock(); - if (mClientMap[ClientIP] > 0) { - mClientMap[ClientIP]--; + try { + std::string ClientIP = c.GetTCPSock().remote_endpoint().address().to_string(); + mClientMapMutex.lock(); + if (mClientMap[ClientIP] > 0) { + mClientMap[ClientIP]--; + } + if (mClientMap[ClientIP] == 0) { + mClientMap.erase(ClientIP); + } + mClientMapMutex.unlock(); + } catch (const std::exception& e) { + beammp_debugf("Failed to disconnect client (already disconnected?). There might be a lingering client in the IP-to-client map. This is not an error."); } - if (mClientMap[ClientIP] == 0) { - mClientMap.erase(ClientIP); - } - mClientMapMutex.unlock(); c.Disconnect(R); }