Skip to content

Commit e731e9d

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/[email protected]
1 parent ca0830e commit e731e9d

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;
@@ -1041,8 +1041,8 @@ ExecAppendAsyncEventWait(AppendState *node)
10411041
}
10421042

10431043
/*
1044-
* No need for further processing if there are no configured events other
1045-
* than the postmaster death event.
1044+
* No need for further processing if none of the subplans configured any
1045+
* events.
10461046
*/
10471047
if (GetNumRegisteredWaitEvents(node->as_eventset) == 1)
10481048
{
@@ -1051,6 +1051,21 @@ ExecAppendAsyncEventWait(AppendState *node)
10511051
return;
10521052
}
10531053

1054+
/*
1055+
* Add the process latch to the set, so that we wake up to process the
1056+
* standard interrupts with CHECK_FOR_INTERRUPTS().
1057+
*
1058+
* NOTE: For historical reasons, it's important that this is added to the
1059+
* WaitEventSet after the ExecAsyncConfigureWait() calls. Namely,
1060+
* postgres_fdw calls "GetNumRegisteredWaitEvents(set) == 1" to check if
1061+
* any other events are in the set. That's a poor design, it's
1062+
* questionable for postgres_fdw to be doing that in the first place, but
1063+
* we cannot change it now. The pattern has possibly been copied to other
1064+
* extensions too.
1065+
*/
1066+
AddWaitEventToSet(node->as_eventset, WL_LATCH_SET, PGINVALID_SOCKET,
1067+
MyLatch, NULL);
1068+
10541069
/* Return at most EVENT_BUFFER_SIZE events in one call. */
10551070
if (nevents > EVENT_BUFFER_SIZE)
10561071
nevents = EVENT_BUFFER_SIZE;
@@ -1092,6 +1107,13 @@ ExecAppendAsyncEventWait(AppendState *node)
10921107
ExecAsyncNotify(areq);
10931108
}
10941109
}
1110+
1111+
/* Handle standard interrupts */
1112+
if ((w->events & WL_LATCH_SET) != 0)
1113+
{
1114+
ResetLatch(MyLatch);
1115+
CHECK_FOR_INTERRUPTS();
1116+
}
10951117
}
10961118
}
10971119

0 commit comments

Comments
 (0)