]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Add guard to prevent recursive memory context logging.
authorFujii Masao <fujii@postgresql.org>
Fri, 19 Dec 2025 03:08:20 +0000 (12:08 +0900)
committerFujii Masao <fujii@postgresql.org>
Fri, 19 Dec 2025 03:09:10 +0000 (12:09 +0900)
commit0fc2f533a96ca843474995bc9dfe9392acbc2df2
treed2612271546e8f95a1b8d6e4bb9aab1c139d6fe6
parent460d97020ac1955a293fe79d2789ae8f35ba69cf
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
src/backend/utils/mmgr/mcxt.c