Yet another deadlock fix attempt

This commit is contained in:
Pablo Marcos 2024-10-13 15:15:58 +02:00 committed by GitHub
parent 326217a039
commit 7b478cb73f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -133,13 +133,15 @@ void QueryMetricLog::finishQuery(const String & query_id, QueryStatusInfoPtr que
add(std::move(elem.value()));
}
/// Take ownership of the task, setting finished to true so that we don't try to schedule it anymore.
auto task = std::move(it->second.task);
it->second.finished = true;
{
/// Take ownership of the task, setting the old one so that we don't try to schedule it anymore.
auto task = std::move(it->second.task);
it->second.task = {};
/// Make sure to always deactivate the task without locking queries_mutex to prevent deadlock.
lock.unlock();
}
/// Make sure to always deactivate the task without locking queries_mutex to prevent deadlock.
lock.unlock();
task->deactivate();
lock.lock();
queries.erase(query_id);
}
@ -175,7 +177,7 @@ std::optional<QueryMetricLogElement> QueryMetricLog::createLogMetricElement(cons
elem.profile_events = query_status.last_profile_events;
}
if (!query_status.finished && schedule_next)
if (query_status.task && schedule_next)
{
query_status.next_collect_time += std::chrono::milliseconds(query_status.interval_milliseconds);
const auto wait_time = std::chrono::duration_cast<std::chrono::milliseconds>(query_status.next_collect_time - std::chrono::system_clock::now()).count();