Add locks on exception throwing.

This commit is contained in:
Yarik Briukhovetskyi 2024-11-19 12:35:42 +01:00 committed by GitHub
parent bdd9243f68
commit 333bba4e6b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 5 deletions

View File

@ -459,7 +459,6 @@ void QueryStatus::ExecutorHolder::remove()
CancellationCode QueryStatus::cancelQuery(CancelReason reason, std::exception_ptr exception) CancellationCode QueryStatus::cancelQuery(CancelReason reason, std::exception_ptr exception)
{ {
{ {
// Lock the mutex to protect the critical section
std::lock_guard<std::mutex> lock(cancel_mutex); std::lock_guard<std::mutex> lock(cancel_mutex);
if (is_killed) if (is_killed)
@ -501,9 +500,12 @@ CancellationCode QueryStatus::cancelQuery(CancelReason reason, std::exception_pt
void QueryStatus::throwProperExceptionIfNeeded(const UInt64 & max_execution_time, const UInt64 & elapsed_ns) const void QueryStatus::throwProperExceptionIfNeeded(const UInt64 & max_execution_time, const UInt64 & elapsed_ns) const
{ {
if (is_killed.load())
{ {
throwProperException(max_execution_time, elapsed_ns); std::lock_guard<std::mutex> lock(cancel_mutex);
if (is_killed)
{
throwProperException(max_execution_time, elapsed_ns);
}
} }
} }
@ -515,7 +517,7 @@ void QueryStatus::throwProperException(const UInt64 & max_execution_time, const
if (cancel_reason == CancelReason::TIMEOUT) if (cancel_reason == CancelReason::TIMEOUT)
throw Exception(ErrorCodes::TIMEOUT_EXCEEDED, "Timeout exceeded: {} maximum: {} ms", additional_error_part, max_execution_time / 1000.0); throw Exception(ErrorCodes::TIMEOUT_EXCEEDED, "Timeout exceeded: {} maximum: {} ms", additional_error_part, max_execution_time / 1000.0);
throw Exception(ErrorCodes::QUERY_WAS_CANCELLED, "Query was cancelled"); throwQueryWasCancelled();
} }
void QueryStatus::addPipelineExecutor(PipelineExecutor * e) void QueryStatus::addPipelineExecutor(PipelineExecutor * e)

View File

@ -116,7 +116,7 @@ protected:
bool is_cancelling { false }; bool is_cancelling { false };
/// KILL was send to the query /// KILL was send to the query
std::atomic<bool> is_killed { false }; std::atomic<bool> is_killed { false };
std::atomic<CancelReason> cancel_reason { CancelReason::UNDEFINED }; CancelReason cancel_reason { CancelReason::UNDEFINED };
std::exception_ptr cancellation_exception; std::exception_ptr cancellation_exception;
mutable std::mutex cancellation_exception_mutex; mutable std::mutex cancellation_exception_mutex;