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).
This commit is contained in:
Lion Kortlepel
2026-04-07 21:19:33 +00:00
parent 8cdee376c6
commit 7925caf1a2
+4
View File
@@ -661,6 +661,7 @@ void TNetwork::DisconnectClient(const std::weak_ptr<TClient> &c, const std::stri
void TNetwork::DisconnectClient(TClient &c, const std::string &R) void TNetwork::DisconnectClient(TClient &c, const std::string &R)
{ {
if (c.IsDisconnected()) return; if (c.IsDisconnected()) return;
try {
std::string ClientIP = c.GetTCPSock().remote_endpoint().address().to_string(); std::string ClientIP = c.GetTCPSock().remote_endpoint().address().to_string();
mClientMapMutex.lock(); mClientMapMutex.lock();
if (mClientMap[ClientIP] > 0) { if (mClientMap[ClientIP] > 0) {
@@ -670,6 +671,9 @@ void TNetwork::DisconnectClient(TClient &c, const std::string &R)
mClientMap.erase(ClientIP); mClientMap.erase(ClientIP);
} }
mClientMapMutex.unlock(); 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.");
}
c.Disconnect(R); c.Disconnect(R);
} }