summaryrefslogtreecommitdiff
path: root/src/backend/commands/async.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/commands/async.c')
-rw-r--r--src/backend/commands/async.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/backend/commands/async.c b/src/backend/commands/async.c
index d8f1408e9e9..10ef8f18546 100644
--- a/src/backend/commands/async.c
+++ b/src/backend/commands/async.c
@@ -2103,6 +2103,8 @@ asyncQueueAdvanceTail(void)
static void
ProcessIncomingNotify(void)
{
+ MemoryContext oldcontext;
+
/* We *must* reset the flag */
notifyInterruptPending = false;
@@ -2117,14 +2119,21 @@ ProcessIncomingNotify(void)
/*
* We must run asyncQueueReadAllNotifications inside a transaction, else
- * bad things happen if it gets an error.
+ * bad things happen if it gets an error. However, we need to preserve
+ * the caller's memory context (typically MessageContext).
*/
+ oldcontext = CurrentMemoryContext;
+
StartTransactionCommand();
asyncQueueReadAllNotifications();
CommitTransactionCommand();
+ /* Caller's context had better not have been transaction-local */
+ Assert(MemoryContextIsValid(oldcontext));
+ MemoryContextSwitchTo(oldcontext);
+
/*
* Must flush the notify messages to ensure frontend gets them promptly.
*/