pgsql: Add guard to prevent recursive memory context logging.

From: Fujii Masao <fujii(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add guard to prevent recursive memory context logging.
Date: 2025-12-19 03:11:25
Message-ID: E1vWQtn-001WqZ-38@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/1a9a49699c21a21b7b30c7a1b3aeb54cfefa3aa0

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

Browse pgsql-committers by date

  From Date Subject
Next Message Fujii Masao 2025-12-19 03:17:01 Re: pgsql: Add function to log the memory contexts of specified backend pro
Previous Message Fujii Masao 2025-12-19 03:11:12 pgsql: Add guard to prevent recursive memory context logging.