فهرست منبع

Fix possible thread race on server shutdown:

- Main thread shutting down server from player request
- Network thread shutting down server due to server shutting down
network
Ivan Savenko 1 سال پیش
والد
کامیت
f8e4e41c39
1فایلهای تغییر یافته به همراه2 افزوده شده و 3 حذف شده
  1. 2 3
      client/CServerHandler.cpp

+ 2 - 3
client/CServerHandler.cpp

@@ -902,6 +902,8 @@ void CServerHandler::onPacketReceived(const std::shared_ptr<INetworkConnection>
 
 void CServerHandler::onDisconnected(const std::shared_ptr<INetworkConnection> & connection, const std::string & errorMessage)
 {
+	boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
+
 	if (connection != networkConnection)
 	{
 		// ServerHandler already closed this connection on its own
@@ -920,8 +922,6 @@ void CServerHandler::onDisconnected(const std::shared_ptr<INetworkConnection> &
 		return;
 	}
 
-	boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
-
 	logNetwork->error("Lost connection to server! Connection has been closed");
 
 	if(client)
@@ -956,7 +956,6 @@ void CServerHandler::waitForServerShutdown()
 	}
 	else
 	{
-		boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
 		if (getState() == EClientState::CONNECTING)
 		{
 			showServerError(CGI->generaltexth->translate("vcmi.server.errors.existingProcess"));