Switch memory contexts in ReinitializeParallelDSM.
authorRobert Haas <[email protected]>
Tue, 16 Dec 2025 15:40:53 +0000 (10:40 -0500)
committerRobert Haas <[email protected]>
Tue, 16 Dec 2025 15:59:04 +0000 (10:59 -0500)
commit1d0fc2499ff2f7b81e1e2c742ccb587c48d0f6d6
tree2535c6598dfcb7964c0987492a7baac19f7e73f0
parentf5927da4ff6c4447109cd00e584a5f29fcc62625
Switch memory contexts in ReinitializeParallelDSM.

We already do this in CreateParallelContext, InitializeParallelDSM, and
LaunchParallelWorkers. I suspect the reason why the matching logic was
omitted from ReinitializeParallelDSM is that I failed to realize that
any memory allocation was happening here -- but shm_mq_attach does
allocate, which could result in a shm_mq_handle being allocated in a
shorter-lived context than the ParallelContext which points to it.

That could result in a crash if the shorter-lived context is freed
before the parallel context is destroyed. As far as I am currently
aware, there is no way to reach a crash using only code that is
present in core PostgreSQL, but extensions could potentially trip
over this. Fixing this in the back-branches appears low-risk, so
back-patch to all supported versions.

Author: Jakub Wartak <[email protected]>
Co-authored-by: Jeevan Chalke <[email protected]>
Backpatch-through: 14
Discussion: http://postgr.es/m/CAKZiRmwfVripa3FGo06=5D1EddpsLu9JY2iJOTgbsxUQ339ogQ@mail.gmail.com
src/backend/access/transam/parallel.c