Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6c07f9e

Browse files
author
Etsuro Fujita
committed
postgres_fdw: Fix subabort cleanup of connections used in asynchronous execution.
Commit 27e1f14 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
1 parent 237d1f3 commit 6c07f9e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

contrib/postgres_fdw/connection.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,10 +1441,17 @@ pgfdw_abort_cleanup(ConnCacheEntry *entry, const char *sql, bool toplevel)
14411441

14421442
entry->have_prep_stmt = false;
14431443
entry->have_error = false;
1444-
/* Also reset per-connection state */
1445-
memset(&entry->state, 0, sizeof(entry->state));
14461444
}
14471445

1446+
/*
1447+
* If pendingAreq of the per-connection state is not NULL, it means that
1448+
* an asynchronous fetch begun by fetch_more_data_begin() was not done
1449+
* successfully and thus the per-connection state was not reset in
1450+
* fetch_more_data(); in that case reset the per-connection state here.
1451+
*/
1452+
if (entry->state.pendingAreq)
1453+
memset(&entry->state, 0, sizeof(entry->state));
1454+
14481455
/* Disarm changing_xact_state if it all worked */
14491456
entry->changing_xact_state = false;
14501457
}

0 commit comments

Comments
 (0)