diff --git a/dbms/src/DataStreams/ParallelAggregatingBlockInputStream.cpp b/dbms/src/DataStreams/ParallelAggregatingBlockInputStream.cpp index 447dfdfbed5..9d9d73b3631 100644 --- a/dbms/src/DataStreams/ParallelAggregatingBlockInputStream.cpp +++ b/dbms/src/DataStreams/ParallelAggregatingBlockInputStream.cpp @@ -195,6 +195,9 @@ void ParallelAggregatingBlockInputStream::Handler::onFinish() void ParallelAggregatingBlockInputStream::Handler::onException(std::exception_ptr & exception, size_t thread_num) { parent.exceptions[thread_num] = exception; + Int32 old_value = -1; + parent.first_exception_index.compare_exchange_strong(old_value, static_cast(thread_num), std::memory_order_seq_cst, std::memory_order_relaxed); + /// can not cancel parent inputStream or the exception might be lost if (!parent.executed) /// kill the processor so ExchangeReceiver will be closed @@ -220,7 +223,8 @@ void ParallelAggregatingBlockInputStream::execute() processor.process(); processor.wait(); - rethrowFirstException(exceptions); + if (first_exception_index != -1) + std::rethrow_exception(exceptions[first_exception_index]); if (isCancelledOrThrowIfKilled()) return; diff --git a/dbms/src/DataStreams/ParallelAggregatingBlockInputStream.h b/dbms/src/DataStreams/ParallelAggregatingBlockInputStream.h index b96fe3ad0e5..b7e9c3fe9a1 100644 --- a/dbms/src/DataStreams/ParallelAggregatingBlockInputStream.h +++ b/dbms/src/DataStreams/ParallelAggregatingBlockInputStream.h @@ -102,6 +102,7 @@ class ParallelAggregatingBlockInputStream : public IProfilingBlockInputStream ManyAggregatedDataVariants many_data; Exceptions exceptions; + std::atomic first_exception_index{-1}; struct ThreadData {