From f4cd34be5ca1d332fa84a65cdc8ea7c2c1a9188b Mon Sep 17 00:00:00 2001 From: Rene Cannao Date: Fri, 13 Feb 2026 16:58:16 +0000 Subject: [PATCH] Fix race condition in monitor_connect_thread Add wait loop for GloMTH initialization before accessing variables. Other monitor threads (MonitorPing, MonitorReadOnly, etc.) already had this pattern, but monitor_connect_thread was missing it. This fixes Valgrind errors about uninitialized values in get_variable_uint16() when strcasecmp reads from memory that hasn't been fully initialized yet. --- lib/MySQL_Monitor.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/MySQL_Monitor.cpp b/lib/MySQL_Monitor.cpp index 03a4ed940..007a08875 100644 --- a/lib/MySQL_Monitor.cpp +++ b/lib/MySQL_Monitor.cpp @@ -1339,6 +1339,11 @@ void * monitor_connect_thread(const std::vector& mmsd assert(!mmsds.empty()); mysql_close(mysql_init(NULL)); MySQL_Monitor_State_Data *mmsd = mmsds.front(); + // Wait for GloMTH to be initialized + while (GloMTH==NULL) { + usleep(50000); + } + usleep(100000); if (!GloMTH) return NULL; // quick exit during shutdown/restart MySQL_Thread * mysql_thr = new MySQL_Thread(); mysql_thr->curtime=monotonic_time();