Skip to content

Commit 004dbbd

Browse files
committed
Handle interrupts while waiting on Append's async subplans
We did not wake up on interrupts while waiting on async events on an async-capable append node. For example, if you tried to cancel the query, nothing would happen until one of the async subplans becomes readable. To fix, add WL_LATCH_SET to the WaitEventSet. Backpatch down to v14 where async Append execution was introduced. Discussion: https://www.postgresql.org/message-id/37a40570-f558-40d3-b5ea-5c2079b3b30b@iki.fi
1 parent fec4342 commit 004dbbd

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/backend/executor/nodeAppend.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ ExecAppendAsyncRequest(AppendState *node, TupleTableSlot **result)
10161016
static void
10171017
ExecAppendAsyncEventWait(AppendState *node)
10181018
{
1019-
int nevents = node->as_nasyncplans + 1;
1019+
int nevents = node->as_nasyncplans + 2;
10201020
long timeout = node->as_syncdone ? -1 : 0;
10211021
WaitEvent occurred_event[EVENT_BUFFER_SIZE];
10221022
int noccurred;
@@ -1043,13 +1043,28 @@ ExecAppendAsyncEventWait(AppendState *node)
10431043
}
10441044

10451045
/*
1046-
* If there are no configured events other than the postmaster death
1047-
* event, we don't need to wait or poll.
1046+
* No need for further processing if none of the subplans configured
1047+
* any events.
10481048
*/
10491049
if (GetNumRegisteredWaitEvents(node->as_eventset) == 1)
10501050
noccurred = 0;
10511051
else
10521052
{
1053+
/*
1054+
* Add the process latch to the set, so that we wake up to process
1055+
* the standard interrupts with CHECK_FOR_INTERRUPTS().
1056+
*
1057+
* NOTE: For historical reasons, it's important that this is added
1058+
* to the WaitEventSet after the ExecAsyncConfigureWait() calls.
1059+
* Namely, postgres_fdw calls "GetNumRegisteredWaitEvents(set) ==
1060+
* 1" to check if any other events are in the set. That's a poor
1061+
* design, it's questionable for postgres_fdw to be doing that in
1062+
* the first place, but we cannot change it now. The pattern has
1063+
* possibly been copied to other extensions too.
1064+
*/
1065+
AddWaitEventToSet(node->as_eventset, WL_LATCH_SET, PGINVALID_SOCKET,
1066+
MyLatch, NULL);
1067+
10531068
/* Return at most EVENT_BUFFER_SIZE events in one call. */
10541069
if (nevents > EVENT_BUFFER_SIZE)
10551070
nevents = EVENT_BUFFER_SIZE;
@@ -1098,6 +1113,13 @@ ExecAppendAsyncEventWait(AppendState *node)
10981113
ExecAsyncNotify(areq);
10991114
}
11001115
}
1116+
1117+
/* Handle standard interrupts */
1118+
if ((w->events & WL_LATCH_SET) != 0)
1119+
{
1120+
ResetLatch(MyLatch);
1121+
CHECK_FOR_INTERRUPTS();
1122+
}
11011123
}
11021124
}
11031125

0 commit comments

Comments
 (0)