Merge pull request #3643 from yandex/fix-parallel-inputs-processor-deadlock

Fix deadlock in ParallelInputsProcessor in case thread creation fails.
This commit is contained in:
alexey-milovidov 2018-11-23 00:30:01 +03:00 committed by GitHub
commit 733ab51089
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -107,9 +107,27 @@ public:
active_threads = max_threads;
threads.reserve(max_threads);
auto thread_group = CurrentThread::getGroup();
try
{
for (size_t i = 0; i < max_threads; ++i)
threads.emplace_back([=] () { thread(thread_group, i); } );
}
catch (...)
{
cancel(false);
wait();
if (active_threads)
{
active_threads = 0;
/// handler.onFinish() is supposed to be called from one of the threads when the number of
/// finished threads reaches max_threads. But since we weren't able to launch all threads,
/// we have to call onFinish() manually here.
handler.onFinish();
}
throw;
}
}
/// Ask all sources to stop earlier than they run out.
void cancel(bool kill)