mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-07-12 17:54:04 +00:00
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:
+12
-8
@@ -661,15 +661,19 @@ void TNetwork::DisconnectClient(const std::weak_ptr<TClient> &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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user