diff --git a/dbms/src/Processors/Executors/PipelineExecutor.cpp b/dbms/src/Processors/Executors/PipelineExecutor.cpp index 038818be16a..e371fdd2765 100644 --- a/dbms/src/Processors/Executors/PipelineExecutor.cpp +++ b/dbms/src/Processors/Executors/PipelineExecutor.cpp @@ -144,14 +144,15 @@ void PipelineExecutor::addJob(UInt64 pid) { auto job = [this, pid]() { - SCOPE_EXIT(event_counter.notify()); + SCOPE_EXIT( + { + std::lock_guard lock(finished_execution_mutex); + finished_execution_queue.push(pid); + } + event_counter.notify() + ); graph[pid].processor->work(); - - { - std::lock_guard lock(finished_execution_mutex); - finished_execution_queue.push(pid); - } }; pool->schedule(createExceptionHandledJob(std::move(job), exception_handler));