aboutsummaryrefslogtreecommitdiff
path: root/contrib/postgres_fdw/connection.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/postgres_fdw/connection.c')
-rw-r--r--contrib/postgres_fdw/connection.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c
index 1c7c76d1d4c..35284419c94 100644
--- a/contrib/postgres_fdw/connection.c
+++ b/contrib/postgres_fdw/connection.c
@@ -977,8 +977,17 @@ pgfdw_xact_callback(XactEvent event, void *arg)
{
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. */
@@ -1109,6 +1118,19 @@ pgfdw_subxact_callback(SubXactEvent event, SubTransactionId mySubid,
curlevel, curlevel);
if (!pgfdw_exec_cleanup_query(entry->conn, sql, false))
abort_cleanup_failure = true;
+ else
+ {
+ /*
+ * 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. */