v1-0001-Do-not-exit-on-postmaster-death-ever-inside-CRIT-.patch

application/octet-stream

Filename: v1-0001-Do-not-exit-on-postmaster-death-ever-inside-CRIT-.patch
Type: application/octet-stream
Part: 0
Message: Re: VM corruption on standby

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v1-0001
Subject: Do not exit on postmaster death ever inside CRIT sections.
File+
src/backend/storage/ipc/waiteventset.c 5 5
From 409f9728681851fef38c78d3a6eb9378bba3d12c Mon Sep 17 00:00:00 2001
From: reshke <reshke@double.cloud>
Date: Thu, 14 Aug 2025 06:24:55 +0000
Subject: [PATCH v1] Do not exit on postmaster death ever inside CRIT sections.

One of critical sections essential invariats is not to allow
any other process to observe half-way made changes.
This inludes requrement of holding locks to modified buffer
until xlog records describing changes are properly created.
PostgreSQL already disallows to process any signal cancellation
inside CRIT section, guaratees process does not release lock
on its buffers too early. This patch does the same inside WaitLatch
facilites, disallowing to exit on Postmaster death event inside CRIT
section.
---
 src/backend/storage/ipc/waiteventset.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/backend/storage/ipc/waiteventset.c b/src/backend/storage/ipc/waiteventset.c
index 7c0e66900f9..26b4a8d0f2b 100644
--- a/src/backend/storage/ipc/waiteventset.c
+++ b/src/backend/storage/ipc/waiteventset.c
@@ -1257,7 +1257,7 @@ WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout,
 			 */
 			if (!PostmasterIsAliveInternal())
 			{
-				if (set->exit_on_postmaster_death)
+				if (set->exit_on_postmaster_death && CritSectionCount == 0)
 					proc_exit(1);
 				occurred_events->fd = PGINVALID_SOCKET;
 				occurred_events->events = WL_POSTMASTER_DEATH;
@@ -1339,7 +1339,7 @@ WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout,
 	 */
 	if (unlikely(set->report_postmaster_not_running))
 	{
-		if (set->exit_on_postmaster_death)
+		if (set->exit_on_postmaster_death && CritSectionCount == 0)
 			proc_exit(1);
 		occurred_events->fd = PGINVALID_SOCKET;
 		occurred_events->events = WL_POSTMASTER_DEATH;
@@ -1411,7 +1411,7 @@ WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout,
 			 */
 			set->report_postmaster_not_running = true;
 
-			if (set->exit_on_postmaster_death)
+			if (set->exit_on_postmaster_death && CritSectionCount == 0)
 				proc_exit(1);
 			occurred_events->fd = PGINVALID_SOCKET;
 			occurred_events->events = WL_POSTMASTER_DEATH;
@@ -1541,7 +1541,7 @@ WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout,
 			 */
 			if (!PostmasterIsAliveInternal())
 			{
-				if (set->exit_on_postmaster_death)
+				if (set->exit_on_postmaster_death && CritSectionCount == 0)
 					proc_exit(1);
 				occurred_events->fd = PGINVALID_SOCKET;
 				occurred_events->events = WL_POSTMASTER_DEATH;
@@ -1752,7 +1752,7 @@ WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout,
 			 */
 			if (!PostmasterIsAliveInternal())
 			{
-				if (set->exit_on_postmaster_death)
+				if (set->exit_on_postmaster_death && CritSectionCount == 0)
 					proc_exit(1);
 				occurred_events->fd = PGINVALID_SOCKET;
 				occurred_events->events = WL_POSTMASTER_DEATH;
-- 
2.43.0