pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix a recently-introduced race condition in LISTEN/NOTIFY handli
Date: Sat, 28 Nov 2020 19:04:03 +0000
Message-ID: <E1kj5Vr-0003Iy-5w@gemulon.postgresql.org> (raw)

Fix a recently-introduced race condition in LISTEN/NOTIFY handling.

Commit 566372b3d fixed some race conditions involving concurrent
SimpleLruTruncate calls, but it introduced new ones in async.c.
A newly-listening backend could attempt to read Notify SLRU pages that
were in process of being truncated, possibly causing an error.  Also,
the QUEUE_TAIL pointer could become set to a value that's not equal to
the queue position of any backend.  While that's fairly harmless in
v13 and up (thanks to commit 51004c717), in older branches it resulted
in near-permanent disabling of the queue truncation logic, so that
continued use of NOTIFY led to queue-fill warnings and eventual
inability to send any more notifies.  (A server restart is enough to
make that go away, but it's still pretty unpleasant.)

The core of the problem is confusion about whether QUEUE_TAIL
represents the "logical" tail of the queue (i.e., the oldest
still-interesting data) or the "physical" tail (the oldest data we've
not yet truncated away).  To fix, split that into two variables.
QUEUE_TAIL regains its definition as the logical tail, and we
introduce a new variable to track the oldest un-truncated page.

Per report from Mikael Gustavsson.  Like the previous patch,
back-patch to all supported branches.

Discussion: https://postgr.es/m/1b8561412e8a4f038d7a491c8b922788@smhi.se

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/f6324bbbe63c5430eee1ffc3cf56fc56ab2c1af8

Modified Files
--------------
src/backend/commands/async.c | 52 +++++++++++++++++++++++++++++++++-----------
1 file changed, 39 insertions(+), 13 deletions(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1kj5Vr-0003Iy-5w@gemulon.postgresql.org>
Permalink:  ../E1kj5Vr-0003Iy-5w@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1kj5Vr-0003Iy-5w@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: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Fix a recently-introduced race condition in LISTEN/NOTIFY handli
  In-Reply-To: <E1kj5Vr-0003Iy-5w@gemulon.postgresql.org>
  References: <E1kj5Vr-0003Iy-5w@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