From 7e82bf3a5395a31e9e474db2d104b8bdd5601769 Mon Sep 17 00:00:00 2001 From: Dennis Felsing Date: Wed, 14 Jun 2023 11:38:28 +0200 Subject: [PATCH] Run MysqlUninit later (fixes #6571) --- src/engine/server/databases/connection_pool.cpp | 15 ++++++++++----- src/engine/server/databases/connection_pool.h | 2 ++ src/engine/server/main.cpp | 6 +++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/engine/server/databases/connection_pool.cpp b/src/engine/server/databases/connection_pool.cpp index 75fb1b2b5..b55b02104 100644 --- a/src/engine/server/databases/connection_pool.cpp +++ b/src/engine/server/databases/connection_pool.cpp @@ -117,8 +117,6 @@ CSqlExecData::CSqlExecData(IConsole *pConsole, CDbConnectionPool::Mode m) : m_Ptr.m_Print.m_Mode = m; } -CDbConnectionPool::~CDbConnectionPool() = default; - void CDbConnectionPool::Print(IConsole *pConsole, Mode DatabaseMode) { m_pShared->m_aQueries[m_InsertIdx++] = std::make_unique(pConsole, DatabaseMode); @@ -466,7 +464,14 @@ bool CDbConnectionPool::ExecSqlFunc(IDbConnection *pConnection, CSqlExecData *pD CDbConnectionPool::CDbConnectionPool() { m_pShared = std::make_shared(); - - thread_init_and_detach(CWorker::Start, new CWorker(m_pShared), "database worker thread"); - thread_init_and_detach(CBackup::Start, new CBackup(m_pShared), "database backup worker thread"); + m_pWorkerThread = thread_init(CWorker::Start, new CWorker(m_pShared), "database worker thread"); + m_pBackupThread = thread_init(CBackup::Start, new CBackup(m_pShared), "database backup worker thread"); +} + +CDbConnectionPool::~CDbConnectionPool() +{ + if(m_pWorkerThread) + thread_wait(m_pWorkerThread); + if(m_pBackupThread) + thread_wait(m_pBackupThread); } diff --git a/src/engine/server/databases/connection_pool.h b/src/engine/server/databases/connection_pool.h index 44e6899e2..040941118 100644 --- a/src/engine/server/databases/connection_pool.h +++ b/src/engine/server/databases/connection_pool.h @@ -124,6 +124,8 @@ private: }; std::shared_ptr m_pShared; + void *m_pWorkerThread = nullptr; + void *m_pBackupThread = nullptr; }; #endif // ENGINE_SERVER_DATABASES_CONNECTION_POOL_H diff --git a/src/engine/server/main.cpp b/src/engine/server/main.cpp index 44938ed9c..5425a16e4 100644 --- a/src/engine/server/main.cpp +++ b/src/engine/server/main.cpp @@ -190,12 +190,12 @@ int main(int argc, const char **argv) dbg_msg("server", "starting..."); int Ret = pServer->Run(); - MysqlUninit(); - secure_random_uninit(); - pServerLogger->OnServerDeletion(); // free delete pKernel; + MysqlUninit(); + secure_random_uninit(); + return Ret; }