Skip to content

Commit 2b44d74

Browse files
committed
Take care to reprocess an uncommitted notify message.
Oversight in my changes to cope with possible errors during message processing; spotted by Joachim Wieland.
1 parent 075d43a commit 2b44d74

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/backend/commands/async.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/commands/async.c,v 1.152 2010/02/17 00:52:09 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/commands/async.c,v 1.153 2010/02/17 16:54:06 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1951,6 +1951,7 @@ asyncQueueReadAllNotifications(void)
19511951
* The function returns true once we have reached the stop position or an
19521952
* uncommitted notification, and false if we have finished with the page.
19531953
* In other words: once it returns true there is no need to look further.
1954+
* The QueuePosition *current is advanced past all processed messages.
19541955
*/
19551956
static bool
19561957
asyncQueueProcessPageEntries(QueuePosition *current,
@@ -1963,10 +1964,12 @@ asyncQueueProcessPageEntries(QueuePosition *current,
19631964

19641965
do
19651966
{
1966-
if (QUEUE_POS_EQUAL(*current, stop))
1967+
QueuePosition thisentry = *current;
1968+
1969+
if (QUEUE_POS_EQUAL(thisentry, stop))
19671970
break;
19681971

1969-
qe = (AsyncQueueEntry *) (page_buffer + QUEUE_POS_OFFSET(*current));
1972+
qe = (AsyncQueueEntry *) (page_buffer + QUEUE_POS_OFFSET(thisentry));
19701973

19711974
/*
19721975
* Advance *current over this message, possibly to the next page.
@@ -2002,8 +2005,14 @@ asyncQueueProcessPageEntries(QueuePosition *current,
20022005
{
20032006
/*
20042007
* The transaction has neither committed nor aborted so far,
2005-
* so we can't process its message yet. Break out of the loop.
2008+
* so we can't process its message yet. Break out of the loop,
2009+
* but first back up *current so we will reprocess the message
2010+
* next time. (Note: it is unlikely but not impossible for
2011+
* TransactionIdDidCommit to fail, so we can't really avoid
2012+
* this advance-then-back-up behavior when dealing with an
2013+
* uncommitted message.)
20062014
*/
2015+
*current = thisentry;
20072016
reachedStop = true;
20082017
break;
20092018
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy