Merge pull request #41343 from azat/deadlock-fix

Fix possible deadlock with async_socket_for_remote/use_hedged_requests and parallel KILL
This commit is contained in:
Alexander Tokmakov 2022-09-20 16:59:31 +03:00 committed by GitHub
commit f9e7451d88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -372,6 +372,12 @@ CancellationCode QueryStatus::cancelQuery(bool)
void QueryStatus::addPipelineExecutor(PipelineExecutor * e)
{
/// In case of asynchronous distributed queries it is possible to call
/// addPipelineExecutor() from the cancelQuery() context, and this will
/// lead to deadlock.
if (is_killed.load())
throw Exception("Query was cancelled", ErrorCodes::QUERY_WAS_CANCELLED);
std::lock_guard lock(executors_mutex);
assert(std::find(executors.begin(), executors.end(), e) == executors.end());
executors.push_back(e);