Resolve shutdown crash/leak if MySQL server is not running

Fixes #12734
This commit is contained in:
leak
2014-08-10 20:28:18 +02:00
parent 9aea8046ce
commit 14cb6e4235
3 changed files with 81 additions and 44 deletions

View File

@@ -87,6 +87,7 @@ bool StartDB();
void StopDB();
void WorldUpdateLoop();
void ClearOnlineAccounts();
void ShutdownThreadPool(std::vector<std::thread>& threadPool);
variables_map GetConsoleArguments(int argc, char** argv, std::string& cfg_file, std::string& cfg_service);
/// Launch the Trinity server
@@ -179,7 +180,10 @@ extern int main(int argc, char** argv)
// Start the databases
if (!StartDB())
{
ShutdownThreadPool(threadPool);
return 1;
}
// Set server offline (not connectable)
LoginDatabase.DirectPExecute("UPDATE realmlist SET flag = (flag & ~%u) | %u WHERE id = '%d'", REALM_FLAG_OFFLINE, REALM_FLAG_INVALID, realmID);
@@ -236,13 +240,7 @@ extern int main(int argc, char** argv)
WorldUpdateLoop();
// Shutdown starts here
_ioService.stop();
for (auto& thread : threadPool)
{
thread.join();
}
ShutdownThreadPool(threadPool);
sScriptMgr->OnShutdown();
@@ -296,6 +294,16 @@ extern int main(int argc, char** argv)
return World::GetExitCode();
}
void ShutdownThreadPool(std::vector<std::thread>& threadPool)
{
_ioService.stop();
for (auto& thread : threadPool)
{
thread.join();
}
}
void WorldUpdateLoop()
{
uint32 realCurrTime = 0;