From f6f61a4bd9cc8d771c3b33feeee5cfc039c5e05d Mon Sep 17 00:00:00 2001 From: Etsuro Fujita Date: Thu, 4 Apr 2024 17:25:00 +0900 Subject: [PATCH] Fix bogus coding in ExecAppendAsyncEventWait(). No configured-by-FDW events would result in "return" directly out of a PG_TRY block, making the exception stack dangling. Repair. Oversight in commit 501cfd07d; back-patch to v14, like that commit, but as we do not have this issue in HEAD (cf. commit 50c67c201), no need to apply this patch to it. In passing, improve a comment about the handling of in-process requests in a postgres_fdw.c function called from this function. Alexander Pyhalov, with comment adjustment/improvement by me. Discussion: https://postgr.es/m/425fa29a429b21b0332737c42a4fdc70%40postgrespro.ru --- contrib/postgres_fdw/postgres_fdw.c | 18 +++++++++-------- src/backend/executor/nodeAppend.c | 31 ++++++++++++++--------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c index c5cada55fb..23a57104e8 100644 --- a/contrib/postgres_fdw/postgres_fdw.c +++ b/contrib/postgres_fdw/postgres_fdw.c @@ -7174,14 +7174,16 @@ postgresForeignAsyncConfigureWait(AsyncRequest *areq) { /* * This is the case when the in-process request was made by another - * Append. Note that it might be useless to process the request, - * because the query might not need tuples from that Append anymore. - * If there are any child subplans of the same parent that are ready - * for new requests, skip the given request. Likewise, if there are - * any configured events other than the postmaster death event, skip - * it. Otherwise, process the in-process request, then begin a fetch - * to configure the event below, because we might otherwise end up - * with no configured events other than the postmaster death event. + * Append. Note that it might be useless to process the request made + * by that Append, because the query might not need tuples from that + * Append anymore; so we avoid processing it to begin a fetch for the + * given request if possible. If there are any child subplans of the + * same parent that are ready for new requests, skip the given + * request. Likewise, if there are any configured events other than + * the postmaster death event, skip it. Otherwise, process the + * in-process request, then begin a fetch to configure the event + * below, because we might otherwise end up with no configured events + * other than the postmaster death event. */ if (!bms_is_empty(requestor->as_needrequest)) return; diff --git a/src/backend/executor/nodeAppend.c b/src/backend/executor/nodeAppend.c index 99818d3ebc..338484bac9 100644 --- a/src/backend/executor/nodeAppend.c +++ b/src/backend/executor/nodeAppend.c @@ -1043,26 +1043,25 @@ ExecAppendAsyncEventWait(AppendState *node) } /* - * No need for further processing if there are no configured events - * other than the postmaster death event. + * If there are no configured events other than the postmaster death + * event, we don't need to wait or poll. */ if (GetNumRegisteredWaitEvents(node->as_eventset) == 1) + noccurred = 0; + else { - FreeWaitEventSet(node->as_eventset); - node->as_eventset = NULL; - return; + /* Return at most EVENT_BUFFER_SIZE events in one call. */ + if (nevents > EVENT_BUFFER_SIZE) + nevents = EVENT_BUFFER_SIZE; + + /* + * If the timeout is -1, wait until at least one event occurs. If + * the timeout is 0, poll for events, but do not wait at all. + */ + noccurred = WaitEventSetWait(node->as_eventset, timeout, + occurred_event, nevents, + WAIT_EVENT_APPEND_READY); } - - /* Return at most EVENT_BUFFER_SIZE events in one call. */ - if (nevents > EVENT_BUFFER_SIZE) - nevents = EVENT_BUFFER_SIZE; - - /* - * If the timeout is -1, wait until at least one event occurs. If the - * timeout is 0, poll for events, but do not wait at all. - */ - noccurred = WaitEventSetWait(node->as_eventset, timeout, occurred_event, - nevents, WAIT_EVENT_APPEND_READY); } PG_FINALLY(); {