pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <heikki.linnakangas@iki.fi>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix losing a sinval catchup signal that arrives during catchup
Date: Thu, 26 Nov 2026 12:33:40 +0000
Message-ID: <E1xWYfU-00000000OYd-0dCd@gemulon.postgresql.org> (raw)

Fix losing a sinval catchup signal that arrives during catchup

If a new catchup signal arrives while we're still processing a
previous catchup signal, the new signal might be lost:

When a backend falls far behind in the shared invalidation queue,
SICleanupQueue() sets its "signaled" flag, and sends it
PROCSIG_CATCHUP_INTERRUPT, which sets the catchupInterruptPending flag
in the receiving backend.  There was a race condition in how
ReceiveSharedInvalidMessages() cleared catchupInterruptPending and
"signaled".  It cleared "signaled" first, after consuming all the
messages, and catchupInterruptPending only after that.  If a new
catchup signal arrived after the "signaled" flag was cleared in
SIGetDataEntries(), but before clearing catchupInterruptPending, the
backend could be left with its "signaled" flag set but
catchupInterruptPending not set.  As a result, other backends would
not send it any more catchup signals, but it would not wake up to
consume the messages until AcceptInvalidationMessages() was called for
some other reason, typically when it next ran a query.

To fix, reset catchupInterruptPending only if "signaled" was not
concurrently re-armed.  Move the responsibility for resetting it into
SICleanupQueue() itself, because it already holds the lock needed to
read "signaled".

No backpatching, since we have no reports from the field about this,
and the consequences are not that severe.

Reviewed-by: Shihao Zhong <zhong950419@gmail.com>
Reviewed-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Discussion: https://www.postgresql.org/message-id/42b2c4f9-511e-4b5c-8edd-b474019ddf29@iki.fi

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/3b249c728fd126c684be77ae834cb7eaa38d0962

Modified Files
--------------
src/backend/storage/ipc/sinval.c    | 16 +++++++++-------
src/backend/storage/ipc/sinvaladt.c | 16 ++++++++++++++++
2 files changed, 25 insertions(+), 7 deletions(-)



Message-ID: <E1xWYfU-00000000OYd-0dCd@gemulon.postgresql.org>
Permalink:  ../E1xWYfU-00000000OYd-0dCd@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xWYfU-00000000OYd-0dCd@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: heikki.linnakangas@iki.fi
  Subject: Re: pgsql: Fix losing a sinval catchup signal that arrives during catchup
  In-Reply-To: <E1xWYfU-00000000OYd-0dCd@gemulon.postgresql.org>
  References: <E1xWYfU-00000000OYd-0dCd@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox