pgsql: Make GetSnapshotData() more resilient on out-of-memory errors

Started by Michael Paquier5 months ago4 messageshackerscommitters
Jump to latest
#1Michael Paquier
michael@paquier.xyz
committers

Make GetSnapshotData() more resilient on out-of-memory errors

If the allocation of Snapshot->subxip fails, a follow-up call of
GetSnapshotData() would see a partially-initialized snapshot, causing a
NULL dereference on reentry when using "subxip" because only "xip" would
be allocated. In the event of an out-of-memory error when allocating
"subxip", "xip" is now reset before throwing an ERROR, so as Snapshots
can be allocated and handled gracefully on retry.

This problem is unlikely going to show up in practice, so no backpatch.

Reported-by: Alexander Lakhin <exclusion@gmail.com>
Author: Matthias van de Meent <boekewurm+postgres@gmail.com>
Discussion: /messages/by-id/e77acaac-a1b3-40b3-99ee-5769b4e453e4@gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/29fb598b9cad898ef851b9a7704f980218057562

Modified Files
--------------
src/backend/storage/ipc/procarray.c | 8 ++++++++
1 file changed, 8 insertions(+)

#2Aleksander Alekseev
aleksander@tigerdata.com
In reply to: Michael Paquier (#1)
committers
Re: pgsql: Make GetSnapshotData() more resilient on out-of-memory errors

Hi Michael,

This problem is unlikely going to show up in practice, so no backpatch.

A customer reported offlist that the issue is reproducible in practice
on PostgreSQL 18. I suggest backpatching this.

--
Best regards,
Aleksander Alekseev

#3Michael Paquier
michael@paquier.xyz
In reply to: Aleksander Alekseev (#2)
hackers
Re: pgsql: Make GetSnapshotData() more resilient on out-of-memory errors

On Mon, Nov 09, 2026 at 11:26:50AM +0300, Aleksander Alekseev wrote:

A customer reported offlist that the issue is reproducible in practice
on PostgreSQL 18. I suggest backpatching this.

I would not mind. Any concerns from others?
--
Michael

#4Michael Paquier
michael@paquier.xyz
In reply to: Michael Paquier (#3)
hackers
Re: pgsql: Make GetSnapshotData() more resilient on out-of-memory errors

On Tue, Nov 10, 2026 at 01:55:29PM +0900, Michael Paquier wrote:

I would not mind. Any concerns from others?

Done this one down to v15. Thanks for the feedback.
--
Michael