From 8d8577b0ad5c637d57ee0956dfdc04cc2355d546 Mon Sep 17 00:00:00 2001 From: Rahim Kanji Date: Thu, 28 Aug 2025 15:52:50 +0500 Subject: [PATCH] Ensure PgSQL_Threads_Handler and PgSQL_HostGroups_Manager objects are released when ProxySQL shuts down or restarts. --- include/PgSQL_HostGroups_Manager.h | 6 ------ include/proxysql_glovars.hpp | 2 +- lib/PgSQL_HostGroups_Manager.cpp | 12 ++---------- lib/PgSQL_Thread.cpp | 4 ++-- lib/ProxySQL_GloVars.cpp | 1 + src/main.cpp | 22 +++++++++++++++++++++- 6 files changed, 27 insertions(+), 20 deletions(-) diff --git a/include/PgSQL_HostGroups_Manager.h b/include/PgSQL_HostGroups_Manager.h index bea625859..1f44aaf11 100644 --- a/include/PgSQL_HostGroups_Manager.h +++ b/include/PgSQL_HostGroups_Manager.h @@ -557,12 +557,6 @@ class PgSQL_HostGroups_Manager : public Base_HostGroups_Manager { SQLite3_result* incoming_pgsql_servers_v2; - std::thread *HGCU_thread; - - std::thread *GTID_syncer_thread; - //pthread_t GTID_syncer_thread_id; - //pthread_t HGCU_thread_id; - char rand_del[8]; pthread_mutex_t pgsql_errors_mutex; umap_pgsql_errors pgsql_errors_umap; diff --git a/include/proxysql_glovars.hpp b/include/proxysql_glovars.hpp index f758662d3..c5b52b2db 100644 --- a/include/proxysql_glovars.hpp +++ b/include/proxysql_glovars.hpp @@ -137,7 +137,7 @@ class ProxySQL_GlobalVariables { char* gr_bootstrap_ssl_key; char* gr_bootstrap_ssl_mode; pthread_mutex_t ext_glomth_mutex; - + pthread_mutex_t ext_glopth_mutex; bool ssl_keylog_enabled; } global; struct mysql { diff --git a/lib/PgSQL_HostGroups_Manager.cpp b/lib/PgSQL_HostGroups_Manager.cpp index 7aa3c9f17..47758aef4 100644 --- a/lib/PgSQL_HostGroups_Manager.cpp +++ b/lib/PgSQL_HostGroups_Manager.cpp @@ -740,19 +740,11 @@ PgSQL_HostGroups_Manager::PgSQL_HostGroups_Manager() { } void PgSQL_HostGroups_Manager::init() { - // gtid initialization; - //GTID_syncer_thread = new std::thread(>ID_syncer_run); - GTID_syncer_thread = nullptr; - - //pthread_create(>ID_syncer_thread_id, NULL, GTID_syncer_run , NULL); + // do nothing here } void PgSQL_HostGroups_Manager::shutdown() { - HGCU_thread->join(); - delete HGCU_thread; - ev_async_send(gtid_ev_loop, gtid_ev_async); - GTID_syncer_thread->join(); - delete GTID_syncer_thread; + // do nothing here } PgSQL_HostGroups_Manager::~PgSQL_HostGroups_Manager() { diff --git a/lib/PgSQL_Thread.cpp b/lib/PgSQL_Thread.cpp index 8461e891e..06ebdf870 100644 --- a/lib/PgSQL_Thread.cpp +++ b/lib/PgSQL_Thread.cpp @@ -3736,7 +3736,7 @@ void PgSQL_Thread::process_all_sessions() { } void PgSQL_Thread::refresh_variables() { - pthread_mutex_lock(&GloVars.global.ext_glomth_mutex); + pthread_mutex_lock(&GloVars.global.ext_glopth_mutex); if (GloPTH == NULL) { return; } @@ -3981,7 +3981,7 @@ void PgSQL_Thread::refresh_variables() { #endif // DEBUG */ GloPTH->wrunlock(); - pthread_mutex_unlock(&GloVars.global.ext_glomth_mutex); + pthread_mutex_unlock(&GloVars.global.ext_glopth_mutex); } PgSQL_Thread::PgSQL_Thread() { diff --git a/lib/ProxySQL_GloVars.cpp b/lib/ProxySQL_GloVars.cpp index 7273fd15b..c59c891b1 100644 --- a/lib/ProxySQL_GloVars.cpp +++ b/lib/ProxySQL_GloVars.cpp @@ -209,6 +209,7 @@ ProxySQL_GlobalVariables::ProxySQL_GlobalVariables() : pthread_mutex_init(&global.start_mutex,NULL); pthread_mutex_init(&checksum_mutex,NULL); pthread_mutex_init(&global.ext_glomth_mutex,NULL); + pthread_mutex_init(&global.ext_glopth_mutex, NULL); epoch_version = 0; checksums_values.updates_cnt = 0; checksums_values.dumped_at = 0; diff --git a/src/main.cpp b/src/main.cpp index 3b79ae04c..71d25c40e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1248,6 +1248,16 @@ void ProxySQL_Main_shutdown_all_modules() { pthread_mutex_unlock(&GloVars.global.ext_glomth_mutex); #ifdef DEBUG std::cerr << "GloMTH shutdown in "; +#endif + } + if (GloPTH) { + cpu_timer t; + pthread_mutex_lock(&GloVars.global.ext_glopth_mutex); + delete GloPTH; + GloPTH = NULL; + pthread_mutex_unlock(&GloVars.global.ext_glopth_mutex); +#ifdef DEBUG + std::cerr << "GloPTH shutdown in "; #endif } if (GloMyLogger) { @@ -1277,12 +1287,22 @@ void ProxySQL_Main_shutdown_all_modules() { std::cerr << "GloAdmin shutdown in "; #endif } + if (MyHGM) { cpu_timer t; MyHGM->shutdown(); delete MyHGM; #ifdef DEBUG - std::cerr << "GloHGM shutdown in "; + std::cerr << "GloMyHGM shutdown in "; +#endif + } + if (PgHGM) + { + cpu_timer t; + PgHGM->shutdown(); + delete PgHGM; +#ifdef DEBUG + std::cerr << "GloPgHGM shutdown in "; #endif } if (GloMyStmt) {