v3-0003-Add-assertion-for-walreceiver-state-invariant-in-.patch

application/octet-stream

Filename: v3-0003-Add-assertion-for-walreceiver-state-invariant-in-.patch
Type: application/octet-stream
Part: 2
Message: Re: BUG #19093: Behavioral change in walreceiver termination between PostgreSQL 14.17 and 14.18

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 v3-0003
Subject: Add assertion for walreceiver state invariant in stream-archive transition
File+
src/backend/access/transam/xlogrecovery.c 7 0
From 082fdf8829091c577465bc1c97cbea71d9a7b6d4 Mon Sep 17 00:00:00 2001
From: alterego655 <824662526@qq.com>
Date: Fri, 31 Oct 2025 18:43:20 +0800
Subject: [PATCH v3 3/3] Add assertion for walreceiver state invariant in
 stream-archive transition

When switching from streaming to archive WAL sources, if walreceiver is not
streaming we avoid calling ShutdownWalRcv(). Since WALRCV_STOPPING state is
only set inside ShutdownWalRcv() and that function blocks until walreceiver
reaches WALRCV_STOPPED, this state should not be observed in the non-shutdown
path.
---
 src/backend/access/transam/xlogrecovery.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c
index d6be98c6e62..c9406eef353 100644
--- a/src/backend/access/transam/xlogrecovery.c
+++ b/src/backend/access/transam/xlogrecovery.c
@@ -3698,6 +3698,13 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
 						XLogShutdownWalRcv();
 					else
 					{
+						/*
+						 * WALRCV_STOPPING state is a transient state while the startup
+						 * process is in ShutdownWalRcv(). It should never appear
+						 * here since we would be waiting for the walreceiver to
+						 * reach WALRCV_STOPPED in that case.
+						 */
+						Assert(WalRcvGetState() != WALRCV_STOPPING);
 						ResetInstallXLogFileSegmentActive();
 					}
 
-- 
2.51.0