From: Álvaro Herrera <alvherre@kurilemu.de>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Avoid unexpected changes of CurrentResourceOwner and CurrentMemo
Date: Fri, 12 Sep 2025 17:01:25 +0000
Message-ID: <E1ux79J-000NRo-16@gemulon.postgresql.org> (raw)
Avoid unexpected changes of CurrentResourceOwner and CurrentMemoryContext
Users of logical decoding can encounter an unexpected change of
CurrentResourceOwner and CurrentMemoryContext. The problem is that,
unlike other call sites of RollbackAndReleaseCurrentSubTransaction(), in
reorderbuffer.c we fail to restore the original values of these global
variables after being clobbered by subtransaction abort. This patch
saves the values prior to the call and restores them eventually.
In addition, logical.c and logicalfuncs.c had a hack to restore resource
owner, presumably because of lack of this restore. Remove that.
Instead, because the test coverage here is not very consistent, add an
Assert() to ensure that the resowner is kept identical; this would make
it easy to detect other cases of bugs were we fail to restore resowner
properly. This could be removed later.
This is arguably an old bug, but there appears to be no reason to
backpatch it and it's risky to do so, so refrain for now.
Author: Antonin Houska <ah@cybertec.at>
Reported-by: Mihail Nikalayeu <mihailnikalayeu@gmail.com>
Reviewed-by: Euler Taveira <euler@eulerto.com>
Discussion: https://postgr.es/m/119497.1756892972@localhost
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/7dcea51c2a4dcf7c512bbd4f618d1d3620f9d3d7
Modified Files
--------------
src/backend/replication/logical/logical.c | 19 +++++++++++--------
src/backend/replication/logical/logicalfuncs.c | 19 +++++++++++--------
src/backend/replication/logical/reorderbuffer.c | 15 +++++++++++++++
3 files changed, 37 insertions(+), 16 deletions(-)
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 using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: alvherre@kurilemu.de, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Avoid unexpected changes of CurrentResourceOwner and CurrentMemo
In-Reply-To: <E1ux79J-000NRo-16@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