pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Fujii Masao <fujii@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Add guard to prevent recursive memory context logging.
Date: Fri, 19 Dec 2025 03:11:00 +0000
Message-ID: <E1vWQtP-001WpE-1M@gemulon.postgresql.org> (raw)

Add guard to prevent recursive memory context logging.

Previously, if memory context logging was triggered repeatedly and
rapidly while a previous request was still being processed, it could
result in recursive calls to ProcessLogMemoryContextInterrupt().
This could lead to infinite recursion and potentially crash the process.

This commit adds a guard to prevent such recursion.
If ProcessLogMemoryContextInterrupt() is already in progress and
logging memory contexts, subsequent calls will exit immediately,
avoiding unintended recursive calls.

While this scenario is unlikely in practice, it's not impossible.
This change adds a safety check to prevent such failures.

Back-patch to v14, where memory context logging was introduced.

Reported-by: Robert Haas <robertmhaas@gmail.com>
Author: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Atsushi Torikoshi <torikoshia@oss.nttdata.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Artem Gavrilov <artem.gavrilov@percona.com>
Discussion: https://postgr.es/m/CA+TgmoZMrv32tbNRrFTvF9iWLnTGqbhYSLVcrHGuwZvCtph0NA@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/3853f61681e850e846150b38cf9f5ebb34523740

Modified Files
--------------
src/backend/utils/mmgr/mcxt.c | 57 ++++++++++++++++++++++++++++++-------------
1 file changed, 40 insertions(+), 17 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1vWQtP-001WpE-1M@gemulon.postgresql.org>
Permalink:  ../E1vWQtP-001WpE-1M@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1vWQtP-001WpE-1M@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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: fujii@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Add guard to prevent recursive memory context logging.
  In-Reply-To: <E1vWQtP-001WpE-1M@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