From 14cb6e4235ebb84ad41d6ceb4eaf56c0b55d9238 Mon Sep 17 00:00:00 2001 From: leak Date: Sun, 10 Aug 2014 20:28:18 +0200 Subject: Resolve shutdown crash/leak if MySQL server is not running Fixes #12734 --- src/server/worldserver/Main.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src/server/worldserver/Main.cpp') diff --git a/src/server/worldserver/Main.cpp b/src/server/worldserver/Main.cpp index a879dca78b9..2c393215f7d 100644 --- a/src/server/worldserver/Main.cpp +++ b/src/server/worldserver/Main.cpp @@ -87,6 +87,7 @@ bool StartDB(); void StopDB(); void WorldUpdateLoop(); void ClearOnlineAccounts(); +void ShutdownThreadPool(std::vector& 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& threadPool) +{ + _ioService.stop(); + + for (auto& thread : threadPool) + { + thread.join(); + } +} + void WorldUpdateLoop() { uint32 realCurrTime = 0; -- cgit v1.2.3