From 9624bc442281b91c6291584dc3e25dcadb4d045d Mon Sep 17 00:00:00 2001 From: Alex Kasko Date: Mon, 20 Apr 2026 23:07:50 +0100 Subject: [PATCH] Backport busy spin fix to 1.5.2 This PR backports the engine PR duckdb/duckdb#22092 to the 1.5 branch of the JDBC driver. Fixes: #667 --- src/duckdb/src/parallel/task_executor.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/duckdb/src/parallel/task_executor.cpp b/src/duckdb/src/parallel/task_executor.cpp index 9487a1427..f7f995e93 100644 --- a/src/duckdb/src/parallel/task_executor.cpp +++ b/src/duckdb/src/parallel/task_executor.cpp @@ -2,6 +2,8 @@ #include "duckdb/parallel/task_notifier.hpp" #include "duckdb/parallel/task_scheduler.hpp" +#include + namespace duckdb { TaskExecutor::TaskExecutor(TaskScheduler &scheduler) @@ -38,14 +40,16 @@ void TaskExecutor::FinishTask() { void TaskExecutor::WorkOnTasks() { // repeatedly execute tasks until we are finished shared_ptr task_from_producer; - while (scheduler.GetTaskFromProducer(*token, task_from_producer)) { - auto res = task_from_producer->Execute(TaskExecutionMode::PROCESS_ALL); - (void)res; - D_ASSERT(res != TaskExecutionResult::TASK_BLOCKED); - task_from_producer.reset(); - } // wait for all active tasks to finish while (completed_tasks != total_tasks) { + if (scheduler.GetTaskFromProducer(*token, task_from_producer)) { + const auto res = task_from_producer->Execute(TaskExecutionMode::PROCESS_ALL); + std::ignore = res; + D_ASSERT(res != TaskExecutionResult::TASK_BLOCKED); + task_from_producer.reset(); + } else { + std::this_thread::yield(); + } } // check if we ran into any errors while checkpointing