Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix possible (likely distributed) query hung #45448

Merged
merged 3 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions src/Processors/Executors/ExecutingGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,34 @@ bool ExecutingGraph::updateNode(uint64_t pid, Queue & queue, Queue & async_queue

void ExecutingGraph::cancel()
{
std::lock_guard guard(processors_mutex);
for (auto & processor : *processors)
processor->cancel();
cancelled = true;
std::exception_ptr exception_ptr;

{
std::lock_guard guard(processors_mutex);
for (auto & processor : *processors)
{
try
{
processor->cancel();
}
catch (...)
{
if (!exception_ptr)
exception_ptr = std::current_exception();

/// Log any exception since:
/// a) they are pretty rare (the only that I know is from
/// RemoteQueryExecutor)
/// b) there can be exception during query execution, and in this
/// case, this exception can be ignored (not showed to the user).
tryLogCurrentException("ExecutingGraph");
}
}
cancelled = true;
}

if (exception_ptr)
std::rethrow_exception(exception_ptr);
}

}
25 changes: 20 additions & 5 deletions src/Processors/Executors/PullingAsyncPipelineExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,35 @@ bool PullingAsyncPipelineExecutor::pull(Block & block, uint64_t milliseconds)

void PullingAsyncPipelineExecutor::cancel()
{
if (!data)
return;

/// Cancel execution if it wasn't finished.
if (data && !data->is_finished && data->executor)
data->executor->cancel();
try
{
if (!data->is_finished && data->executor)
data->executor->cancel();
}
catch (...)
{
/// Store exception only of during query execution there was no
/// exception, since only one exception can be re-thrown.
if (!data->has_exception)
{
data->exception = std::current_exception();
data->has_exception = true;
}
}

/// The following code is needed to rethrow exception from PipelineExecutor.
/// It could have been thrown from pull(), but we will not likely call it again.

/// Join thread here to wait for possible exception.
if (data && data->thread.joinable())
if (data->thread.joinable())
data->thread.join();

/// Rethrow exception to not swallow it in destructor.
if (data)
data->rethrowExceptionIfHas();
data->rethrowExceptionIfHas();
}

Chunk PullingAsyncPipelineExecutor::getTotals()
Expand Down