From: Andres Freund <andres@anarazel.de>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Michael Paquier <michael.paquier@gmail.com>
Cc: Ben Chobot <bench@silentmedia.com>
Cc: PostgreSQL mailing lists <pgsql-bugs@postgresql.org>
Subject: Re: pg_logical_slot_peek_changes crashes postgres when called from inside pl/pgsql
Date: Thu, 5 Oct 2017 16:01:05 -0700
Message-ID: <20171005230105.qv2yrtadbkbc5y5r@alap3.anarazel.de> (raw)
In-Reply-To: <32374.1507239819@sss.pgh.pa.us>
References: <73FBA179-C68C-4540-9473-71E865408B15@silentmedia.com>
<CAB7nPqRZhE53NYVyOf5-WW6eoN9ZJhg6QeDDyfRfyZj4ESeQFA@mail.gmail.com>
<8637.1507217920@sss.pgh.pa.us>
<20171005211058.z5obk2c2e7zvauk6@alap3.anarazel.de>
<32374.1507239819@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
Hi,
On 2017-10-05 17:43:39 -0400, Tom Lane wrote:
> Andres Freund <andres@anarazel.de> writes:
> > On 2017-10-05 11:38:40 -0400, Tom Lane wrote:
> >> I wonder why ReorderBufferCommit does this:
> >> ...
>
> > I'm not sure what the problem is that you're seeing?
>
> Nah, I take that back. The AbortCurrentTransaction call looks funny
> (and is sadly underdocumented) but it's not invalid to call it and
> then call RollbackAndReleaseCurrentSubTransaction.
It's not perfectly documented, but there's some:
/*
* Decoding needs access to syscaches et al., which in turn use
* heavyweight locks and such. Thus we need to have enough state around to
* keep track of those. The easiest way is to simply use a transaction
* internally. That also allows us to easily enforce that nothing writes
* to the database by checking for xid assignments.
*
* When we're called via the SQL SRF there's already a transaction
* started, so start an explicit subtransaction there.
*/
...
/*
* Aborting the current (sub-)transaction as a whole has the right
* semantics. We want all locks acquired in here to be released, not
* reassigned to the parent and we do not want any database access
* have persistent effects.
*/
> 2. The "MemoryContextResetAndDeleteChildren(_SPI_current->execCxt)"
> call, further up, is deleting a still-live executor state tree,
> as well as the logical-decoding context that is a child of that
> executor query context. So if you get past the Assert you'll still
> crash later on.
Right. That's why just adding found && to the entire if "works", as it
avoids that part as well.
> I'm not sure about a good way to fix #2 without re-introducing the memory
> leaks that call was added to fix (cf 7ec1c5a86). It's slightly annoying
> at this point that we got rid of the SPI_push/SPI_pop mechanism, because
> we could perhaps have used a check of the _SPI_curid value to distinguish
> a SPI context we should clean up from one we shouldn't. But that ship has
> sailed, and even if we wanted to undo that change there'd still be the
> matter of how to fix the bugs that prompted removing SPI_push/SPI_pop.
I think I don't fully understand what 7ec1c5a86 is trying to
achieve. Unfortunately reading the commit message and comment hasn't
cleared it up much so far. Why do we want to clean up memory in a
subtransaction that's above the one aborted? I can't yet meaningfully
comment on your proposals before fully understanding, sorry.
Greetings,
Andres Freund
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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-bugs@postgresql.org
Cc: andres@anarazel.de, tgl@sss.pgh.pa.us, michael.paquier@gmail.com, bench@silentmedia.com
Subject: Re: pg_logical_slot_peek_changes crashes postgres when called from inside pl/pgsql
In-Reply-To: <20171005230105.qv2yrtadbkbc5y5r@alap3.anarazel.de>
References: <73FBA179-C68C-4540-9473-71E865408B15@silentmedia.com> <CAB7nPqRZhE53NYVyOf5-WW6eoN9ZJhg6QeDDyfRfyZj4ESeQFA@mail.gmail.com> <8637.1507217920@sss.pgh.pa.us> <20171005211058.z5obk2c2e7zvauk6@alap3.anarazel.de> <32374.1507239819@sss.pgh.pa.us> <20171005230105.qv2yrtadbkbc5y5r@alap3.anarazel.de>
* 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