fix seemingly extremely rare race condition leading to exception when joining a singleplayer internal server

happened when the client thread called universeServer->setPause (which locks m_clientsLock) between the client id being added to m_clients and the connection being added to m_connectionServer
This commit is contained in:
Kae 2024-06-28 17:09:13 +10:00
parent 4120a289db
commit bb5387fbdb

View File

@ -1679,6 +1679,7 @@ void UniverseServer::acceptConnection(UniverseConnection connection, Maybe<HostA
auto clientContext = make_shared<ServerClientContext>(clientId, remoteAddress, clientConnect->playerUuid, auto clientContext = make_shared<ServerClientContext>(clientId, remoteAddress, clientConnect->playerUuid,
clientConnect->playerName, clientConnect->playerSpecies, administrator, clientConnect->shipChunks); clientConnect->playerName, clientConnect->playerSpecies, administrator, clientConnect->shipChunks);
m_clients.add(clientId, clientContext); m_clients.add(clientId, clientContext);
m_connectionServer->addConnection(clientId, std::move(connection));
clientsLocker.unlock(); clientsLocker.unlock();
clientContext->registerRpcHandlers(m_teamManager->rpcHandlers()); clientContext->registerRpcHandlers(m_teamManager->rpcHandlers());
@ -1700,8 +1701,6 @@ void UniverseServer::acceptConnection(UniverseConnection connection, Maybe<HostA
clientContext->setAdmin(false); clientContext->setAdmin(false);
clientContext->setShipUpgrades(clientConnect->shipUpgrades); clientContext->setShipUpgrades(clientConnect->shipUpgrades);
m_connectionServer->addConnection(clientId, std::move(connection));
m_chatProcessor->connectClient(clientId, clientConnect->playerName); m_chatProcessor->connectClient(clientId, clientConnect->playerName);
m_connectionServer->sendPackets(clientId, { m_connectionServer->sendPackets(clientId, {