fix: avoid potential race conditions when updating the executor (#45230)

issue: #43040

Signed-off-by: Shawn Wang <shawn.wang@zilliz.com>
This commit is contained in:
sparknack 2025-11-04 14:25:33 +08:00 committed by GitHub
parent ab11fddc66
commit 40b5e6b134
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -359,15 +359,16 @@ class FileWriteWorkerPool {
bool
AddTask(std::function<void()> task) {
std::lock_guard<std::mutex> lock(executor_mutex_);
if (executor_ == nullptr) {
return false;
}
std::lock_guard<std::mutex> lock(executor_mutex_);
executor_->add(std::move(task));
return true;
}
~FileWriteWorkerPool() {
std::lock_guard<std::mutex> lock(executor_mutex_);
if (executor_ != nullptr) {
executor_->stop();
executor_->join();