From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@postgresql.org
Subject: pgsql: Fix subtransaction cleanup after an outer-subtransaction portal
Date: Fri, 04 Sep 2015 17:37:34 +0000
Message-ID: <E1ZXuve-0006q5-90@gemulon.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-committers>
Fix subtransaction cleanup after an outer-subtransaction portal fails.
Formerly, we treated only portals created in the current subtransaction as
having failed during subtransaction abort. However, if the error occurred
while running a portal created in an outer subtransaction (ie, a cursor
declared before the last savepoint), that has to be considered broken too.
To allow reliable detection of which ones those are, add a bookkeeping
field to struct Portal that tracks the innermost subtransaction in which
each portal has actually been executed. (Without this, we'd end up
failing portals containing functions that had called the subtransaction,
thereby breaking plpgsql exception blocks completely.)
In addition, when we fail an outer-subtransaction Portal, transfer its
resources into the subtransaction's resource owner, so that they're
released early in cleanup of the subxact. This fixes a problem reported by
Jim Nasby in which a function executed in an outer-subtransaction cursor
could cause an Assert failure or crash by referencing a relation created
within the inner subtransaction.
The proximate cause of the Assert failure is that AtEOSubXact_RelationCache
assumed it could blow away a relcache entry without first checking that the
entry had zero refcount. That was a bad idea on its own terms, so add such
a check there, and to the similar coding in AtEOXact_RelationCache. This
provides an independent safety measure in case there are still ways to
provoke the situation despite the Portal-level changes.
This has been broken since subtransactions were invented, so back-patch
to all supported branches.
Tom Lane and Michael Paquier
Branch
------
REL9_5_STABLE
Details
-------
http://git.postgresql.org/pg/commitdiff/a2538da89f664671d1790cb8dbb4b94849ed923c
Modified Files
--------------
src/backend/access/transam/xact.c | 1 +
src/backend/commands/portalcmds.c | 6 +-
src/backend/tcop/pquery.c | 12 +---
src/backend/utils/cache/relcache.c | 35 +++++++++++-
src/backend/utils/mmgr/portalmem.c | 82 +++++++++++++++++++++++++---
src/include/utils/portal.h | 12 +++-
src/test/regress/expected/transactions.out | 46 ++++++++++++++++
src/test/regress/sql/transactions.sql | 32 +++++++++++
8 files changed, 197 insertions(+), 29 deletions(-)
--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers
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 subtransaction cleanup after an outer-subtransaction portal
In-Reply-To: <E1ZXuve-0006q5-90@gemulon.postgresql.org>
References: <E1ZXuve-0006q5-90@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