aboutsummaryrefslogtreecommitdiff
path: root/contrib/postgres_fdw/connection.c
diff options
context:
space:
mode:
authorEtsuro Fujita <efujita@postgresql.org>2022-01-21 17:45:00 +0900
committerEtsuro Fujita <efujita@postgresql.org>2022-01-21 17:45:00 +0900
commit6c07f9ebce1579612c4ed9076159f9e942e50f9d (patch)
tree0832a3c9718df2eee69cb8f2b959405744df50f8 /contrib/postgres_fdw/connection.c
parent237d1f317240b60b3fff698f4e9b184d1db83a6e (diff)
downloadpostgresql-6c07f9ebce1579612c4ed9076159f9e942e50f9d.tar.gz
postgresql-6c07f9ebce1579612c4ed9076159f9e942e50f9d.zip
postgres_fdw: Fix subabort cleanup of connections used in asynchronous execution.
Commit 27e1f1456 resets the per-connection states of connections used to scan foreign tables asynchronously during abort cleanup at main transaction end, but it failed to do so during subabort cleanup at subtransaction end, leading to a segmentation fault when re-executing an asynchronous-foreign-table-scan query in a transaction that was cancelled in a subtransaction of it. Fix by modifying pgfdw_abort_cleanup() to reset the per-connection state of a given connection also when called for subabort cleanup. Also, modify that function to do the reset in both the abort-cleanup and subabort-cleanup cases if necessary, to save cycles, and improve a comment on it a little bit. Back-patch to v14 where the aforesaid commit came in. Reviewed by Alexander Pyhalov Discussion: https://postgr.es/m/CAPmGK14cCV-JA7kNsyt2EUTKvZ4xkr2LNRthi1U1C3cqfGppAw@mail.gmail.com
Diffstat (limited to 'contrib/postgres_fdw/connection.c')
-rw-r--r--contrib/postgres_fdw/connection.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c
index 4d64dfebf6e..29fcb6a76eb 100644
--- a/contrib/postgres_fdw/connection.c
+++ b/contrib/postgres_fdw/connection.c
@@ -1441,10 +1441,17 @@ pgfdw_abort_cleanup(ConnCacheEntry *entry, const char *sql, bool toplevel)
entry->have_prep_stmt = false;
entry->have_error = false;
- /* Also reset per-connection state */
- memset(&entry->state, 0, sizeof(entry->state));
}
+ /*
+ * If pendingAreq of the per-connection state is not NULL, it means that
+ * an asynchronous fetch begun by fetch_more_data_begin() was not done
+ * successfully and thus the per-connection state was not reset in
+ * fetch_more_data(); in that case reset the per-connection state here.
+ */
+ if (entry->state.pendingAreq)
+ memset(&entry->state, 0, sizeof(entry->state));
+
/* Disarm changing_xact_state if it all worked */
entry->changing_xact_state = false;
}