[Bug Fix] Fix for undefined MySQL library behavior. (#2834)

* MYSQL objects cannot be copied in a well defined way, this removes the copy and replaces it with another connection

* Change to share underlying pointers.

* Push up mutex changes

* Post rebase

* Formatting

---------

Co-authored-by: KimLS <KimLS@peqtgc.com>
Co-authored-by: Akkadius <akkadius1@gmail.com>
This commit is contained in:
Alex
2023-02-24 18:14:55 -08:00
committed by GitHub
parent bad631df59
commit de2dfc1a7e
12 changed files with 162 additions and 61 deletions
+12 -4
View File
@@ -231,6 +231,8 @@ int main(int argc, char** argv) {
worldserver.SetLauncherName("NONE");
}
auto mutex = new Mutex;
LogInfo("Connecting to MySQL");
if (!database.Connect(
Config->DatabaseHost.c_str(),
@@ -242,9 +244,7 @@ int main(int argc, char** argv) {
return 1;
}
/**
* Multi-tenancy: Content Database
*/
// Multi-tenancy: Content Database
if (!Config->ContentDbHost.empty()) {
if (!content_db.Connect(
Config->ContentDbHost.c_str() ,
@@ -258,7 +258,12 @@ int main(int argc, char** argv) {
return 1;
}
} else {
content_db.SetMysql(database.getMySQL());
content_db.SetMySQL(database);
// when database and content_db share the same underlying mysql connection
// it needs to be protected by a shared mutex otherwise we produce concurrency issues
// when database actions are occurring in different threads
database.SetMutex(mutex);
content_db.SetMutex(mutex);
}
/* Register Log System and Settings */
@@ -613,6 +618,9 @@ int main(int argc, char** argv) {
safe_delete(parse);
LogInfo("Proper zone shutdown complete.");
LogSys.CloseFileLogs();
safe_delete(mutex);
return 0;
}