diff options
Diffstat (limited to 'src/backend/commands/async.c')
-rw-r--r-- | src/backend/commands/async.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/backend/commands/async.c b/src/backend/commands/async.c index 409fece1e06..fff1aad83ed 100644 --- a/src/backend/commands/async.c +++ b/src/backend/commands/async.c @@ -2250,6 +2250,8 @@ asyncQueueAdvanceTail(void) static void ProcessIncomingNotify(bool flush) { + MemoryContext oldcontext; + /* We *must* reset the flag */ notifyInterruptPending = false; @@ -2264,14 +2266,21 @@ ProcessIncomingNotify(bool flush) /* * 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); + /* * If this isn't an end-of-command case, we must flush the notify messages * to ensure frontend gets them promptly. |