pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix race condition in snapshot caching when 2PC is used.
Date: Tue, 18 Aug 2020 23:37:43 +0000
Message-ID: <E1k8BAl-00040m-SM@gemulon.postgresql.org> (raw)

Fix race condition in snapshot caching when 2PC is used.

When preparing a transaction xactCompletionCount needs to be
incremented, even though the transaction has not committed
yet. Otherwise the snapshot used within the transaction otherwise can
get reused outside of the prepared transaction. As GetSnapshotData()
does not include the current xid when building a snapshot, reuse would
not be correct.

Somewhat surprisingly the regression tests only rarely show incorrect
results without the fix. The reason for that is that often the
snapshot's xmax will be >= the backend xid, yielding a snapshot that
is correct, despite the bug.

I'm working on a reliable test for the bug, but it seems worth seeing
whether this fixes all the BF failures while I do.

Author: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/E1k7tGP-0005V0-5k@gemulon.postgresql.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/07f32fcd23ac81898ed47f88beb569c631a2f223

Modified Files
--------------
src/backend/storage/ipc/procarray.c | 9 +++++++++
1 file changed, 9 insertions(+)



view thread (8+ messages)  latest in thread

Message-ID: <E1k8BAl-00040m-SM@gemulon.postgresql.org>
Permalink:  ../E1k8BAl-00040m-SM@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1k8BAl-00040m-SM@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: andres@anarazel.de
  Subject: Re: pgsql: Fix race condition in snapshot caching when 2PC is used.
  In-Reply-To: <E1k8BAl-00040m-SM@gemulon.postgresql.org>
  References: <E1k8BAl-00040m-SM@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