Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix interruption crash #584

Merged
merged 2 commits into from
Feb 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/pgduckdb_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,22 @@ ExecuteQuery(DuckdbScanState *state) {
auto &executor = duckdb::Executor::Get(*connection->context);
// Wait for all tasks to terminate
executor.CancelTasks();

try {
// When the "Query cancelled" exception below is thrown,
// various destructors are called, among which `PostgresTableReader`'s
// which cleanup the PG state. If an exception is thrown during
// the stack unwinding and call to PG function, it results in an
// undefined behavior which materialize as a process crash.
// So to avoid that, we eagerly consume the pending tasks.
do {
execution_result = pending->ExecuteTask();
} while (execution_result != duckdb::PendingExecutionResult::EXECUTION_ERROR &&
execution_result != duckdb::PendingExecutionResult::NO_TASKS_AVAILABLE);

pending->Close();
} catch (std::exception &ex) {
}
// Delete the scan state
// Process the interrupt on the Postgres side
ProcessInterrupts();
Expand Down