Merge pull request #39132 from ClickHouse/fix-data-race-in-completed-pipeline-executor

Fix data race in CompletedPipelineExecutor.
This commit is contained in:
Nikolai Kochetov 2022-07-13 13:39:44 +02:00 committed by GitHub
commit 4f8cc871eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -72,9 +72,11 @@ void CompletedPipelineExecutor::execute()
data->executor = std::make_shared<PipelineExecutor>(pipeline.processors, pipeline.process_list_element);
data->executor->setReadProgressCallback(pipeline.getReadProgressCallback());
auto func = [&, thread_group = CurrentThread::getGroup()]()
/// Avoid passing this to labmda, copy ptr to data instead.
/// Destructor of unique_ptr copy raw ptr into local variable first, only then calls object destructor.
auto func = [data_ptr = data.get(), num_threads = pipeline.getNumThreads(), thread_group = CurrentThread::getGroup()]()
{
threadFunction(*data, thread_group, pipeline.getNumThreads());
threadFunction(*data_ptr, thread_group, num_threads);
};
data->thread = ThreadFromGlobalPool(std::move(func));