Skip to content

Commit 6c3f9eb

Browse files
committed
Fix a crash when an exception is thrown in postprocessing
Postprocessing (like building indexes) on output tables happens in parallel. If there is a problem an exception is thrown which is forwarded to the main thread. Here the normal exception handling will clean up everything including the table datastructures still used by the postprocessing of the other tables which might still be in flight. We fix this by storing the exception, waiting for all threads to finish and only then passing on the exception. It is rather unlikely that we'll see this problem in the pgsql output because tables are more or less hardcoded there. It is more likely in the flex output, where users have many options of creating some havoc with unusual table definitions or so. In the flex output we store a pointer to the table so that we can print its name to help narrowing down the problem somewhat.
1 parent 1f708bd commit 6c3f9eb

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/output-flex.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,8 +1076,22 @@ void output_flex_t::stop()
10761076

10771077
void output_flex_t::wait()
10781078
{
1079+
std::exception_ptr eptr;
1080+
flex_table_t const *table_with_error = nullptr;
1081+
10791082
for (auto &table : m_table_connections) {
1080-
table.task_wait();
1083+
try {
1084+
table.task_wait();
1085+
} catch (...) {
1086+
eptr = std::current_exception();
1087+
table_with_error = &table.table();
1088+
}
1089+
}
1090+
1091+
if (eptr) {
1092+
log_error("Error while doing postprocessing on table '{}':",
1093+
table_with_error->name());
1094+
std::rethrow_exception(eptr);
10811095
}
10821096
}
10831097

src/output-pgsql.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,16 @@ void output_pgsql_t::stop()
159159

160160
void output_pgsql_t::wait()
161161
{
162+
std::exception_ptr eptr;
162163
for (auto &t : m_tables) {
163-
t->task_wait();
164+
try {
165+
t->task_wait();
166+
} catch (...) {
167+
eptr = std::current_exception();
168+
}
169+
}
170+
if (eptr) {
171+
std::rethrow_exception(eptr);
164172
}
165173
}
166174

0 commit comments

Comments
 (0)