From c2a62b717a0de9011912dbcbf019287d7394795c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 16 Jan 2026 06:51:22 +0000 Subject: [PATCH 1/3] Initial plan From 5b85a1e4500a965ad87ec5ebc58fa43e8d7d5e2d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 16 Jan 2026 06:55:37 +0000 Subject: [PATCH 2/3] Fix concurrent issue in MariaModule by adding mutex synchronization - Added mutable std::mutex groups_mutex_ to MariaModule class - Updated ResizeGroups() and SetGroup() to protect vector modification with mutex - Updated ExtThdStart() to use mutex and check for nullptr before dereferencing - Updated ExtThdEnd() to use mutex and check for nullptr before dereferencing - Updated Process() to use mutex and check for nullptr before dereferencing - Updated HasTask() to use mutex and check for nullptr before dereferencing Co-authored-by: githubzilla <10080336+githubzilla@users.noreply.github.com> --- sql/threadpool_generic.cc | 45 ++++++++++++++++++++++++++++++--------- sql/threadpool_generic.h | 13 +++++++++-- 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/sql/threadpool_generic.cc b/sql/threadpool_generic.cc index f791ed03d5b..e0d1707269a 100644 --- a/sql/threadpool_generic.cc +++ b/sql/threadpool_generic.cc @@ -2539,22 +2539,38 @@ bool thread_group_t::HasActiveWorker() const #ifdef ELOQ_MODULE_ENABLED void MariaModule::ExtThdStart(int thd_id) { - if (thd_id < 0 || (size_t) thd_id >= groups_.size()) + thread_group_t *group = nullptr; + { + std::lock_guard lk(groups_mutex_); + if (thd_id >= 0 && (size_t)thd_id < groups_.size()) { + group = groups_[thd_id]; + } + } + + if (group == nullptr) { return; } SetIsSqlThd(false); - groups_[thd_id]->ext_worker_active_.store(true, std::memory_order_relaxed); + group->ext_worker_active_.store(true, std::memory_order_relaxed); } void MariaModule::ExtThdEnd(int thd_id) { - if (thd_id < 0 || (size_t) thd_id >= groups_.size()) + thread_group_t *group = nullptr; + { + std::lock_guard lk(groups_mutex_); + if (thd_id >= 0 && (size_t)thd_id < groups_.size()) { + group = groups_[thd_id]; + } + } + + if (group == nullptr) { return; } - thread_group_t *group = groups_[thd_id]; + group->ext_worker_active_.store(false, std::memory_order_relaxed); mysql_mutex_lock(&group->mutex); @@ -2575,13 +2591,15 @@ void MariaModule::ExtThdEnd(int thd_id) void MariaModule::Process(int thd_id) { - if (thd_id < 0 || (size_t) thd_id >= groups_.size()) + thread_group_t *group = nullptr; { - return; + std::lock_guard lk(groups_mutex_); + if (thd_id >= 0 && (size_t)thd_id < groups_.size()) { + group = groups_[thd_id]; + } } - thread_group_t *group = groups_[thd_id]; - if (group->shutdown.load(std::memory_order_relaxed)) + if (group == nullptr || group->shutdown.load(std::memory_order_relaxed)) { return; } @@ -2673,12 +2691,19 @@ void MariaModule::Process(int thd_id) bool MariaModule::HasTask(int thd_id) const { - if (thd_id < 0 || (size_t) thd_id >= groups_.size()) + thread_group_t *group = nullptr; + { + std::lock_guard lk(groups_mutex_); + if (thd_id >= 0 && (size_t)thd_id < groups_.size()) { + group = groups_[thd_id]; + } + } + + if (group == nullptr) { return false; } - thread_group_t *group= groups_[thd_id]; CoroutineInfo *coro_info= group->coroutine_info_.get(); return !coro_info->req_queue_.IsEmpty() || !coro_info->resume_queue_.IsEmpty() || diff --git a/sql/threadpool_generic.h b/sql/threadpool_generic.h index 5502540dbb7..ee855d4cd0b 100644 --- a/sql/threadpool_generic.h +++ b/sql/threadpool_generic.h @@ -251,11 +251,20 @@ class MariaModule : public eloq::EloqModule void Process(int thd_id) override; bool HasTask(int thd_id) const override; - void ResizeGroups(size_t size) { groups_.resize(size, nullptr); } - void SetGroup(size_t gid, thread_group_t *group) { groups_[gid]= group; } + void ResizeGroups(size_t size) + { + std::lock_guard lk(groups_mutex_); + groups_.resize(size, nullptr); + } + void SetGroup(size_t gid, thread_group_t *group) + { + std::lock_guard lk(groups_mutex_); + groups_[gid]= group; + } private: std::vector groups_; + mutable std::mutex groups_mutex_; }; #endif From 0545d763df823e538bfd6181dd54000a72d79819 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 16 Jan 2026 06:57:46 +0000 Subject: [PATCH 3/3] Add bounds checking to SetGroup method Added defensive bounds checking in SetGroup() to prevent potential out-of-bounds access. Fixed code style to use space around assignment operator. Co-authored-by: githubzilla <10080336+githubzilla@users.noreply.github.com> --- sql/threadpool_generic.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sql/threadpool_generic.h b/sql/threadpool_generic.h index ee855d4cd0b..5c553d569a9 100644 --- a/sql/threadpool_generic.h +++ b/sql/threadpool_generic.h @@ -259,7 +259,9 @@ class MariaModule : public eloq::EloqModule void SetGroup(size_t gid, thread_group_t *group) { std::lock_guard lk(groups_mutex_); - groups_[gid]= group; + if (gid < groups_.size()) { + groups_[gid] = group; + } } private: