From 12100bb9c041c660eaad675d8e6ed69b49270009 Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Date: Fri, 9 Sep 2022 17:06:47 +0900
Subject: [PATCH v1] Do not skip calling XLogShutdownWalRcv()

XLogShutdownWalRcv() only stops wal receiver but also flips down the
InstallXLogFileSegmentActive flag.  The function is not called when
entering archive recovery mode with walreceiver already stopped. Thus
archive recovery afterwards faces an assertion failure on the flag in
that case.

Fix this by always calling the function to keep
InstallXLogFileSegmentActive consistent.
---
 src/backend/access/transam/xlogrecovery.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/backend/access/transam/xlogrecovery.c b/src/backend/access/transam/xlogrecovery.c
index 9a80084a68..20bd1f1d2e 100644
--- a/src/backend/access/transam/xlogrecovery.c
+++ b/src/backend/access/transam/xlogrecovery.c
@@ -3532,8 +3532,7 @@ WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
 					 * walreceiver is not active, so that it won't overwrite
 					 * WAL that we restore from archive.
 					 */
-					if (WalRcvStreaming())
-						XLogShutdownWalRcv();
+					XLogShutdownWalRcv();
 
 					/*
 					 * Before we sleep, re-scan for possible new timelines if
-- 
2.31.1

