Add guard to prevent recursive memory context logging. REL_14_STABLE github/REL_14_STABLE
authorFujii Masao <[email protected]>
Fri, 19 Dec 2025 03:08:20 +0000 (12:08 +0900)
committerFujii Masao <[email protected]>
Fri, 19 Dec 2025 03:09:16 +0000 (12:09 +0900)
commit1a9a49699c21a21b7b30c7a1b3aeb54cfefa3aa0
tree18c6f7380565fccbdffcf03616565d01c843edfc
parentab42568695c0ddb9f3d4c2fedcc003a8b8eb15f7
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 <[email protected]>
Author: Fujii Masao <[email protected]>
Reviewed-by: Atsushi Torikoshi <[email protected]>
Reviewed-by: Robert Haas <[email protected]>
Reviewed-by: Artem Gavrilov <[email protected]>
Discussion: https://postgr.es/m/CA+TgmoZMrv32tbNRrFTvF9iWLnTGqbhYSLVcrHGuwZvCtph0NA@mail.gmail.com
Backpatch-through: 14
src/backend/utils/mmgr/mcxt.c