From ac5f7ebb24a021a69a851e31d860af89591424db Mon Sep 17 00:00:00 2001
From: alterego655 <824662526@qq.com>
Date: Fri, 24 Jul 2026 16:37:20 +0800
Subject: [PATCH v6 4/5] Clarify LSN waiter cleanup after wakeup

WaitLSNWakeup() can be called by several processes, not only the startup
process.  Update the cleanup comment to explain that another process may
remove the waiter before waking it and that inHeap prevents double
deletion.
---
 src/backend/access/transam/xlogwait.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/backend/access/transam/xlogwait.c b/src/backend/access/transam/xlogwait.c
index 6b501fef7ba..9e05505344f 100644
--- a/src/backend/access/transam/xlogwait.c
+++ b/src/backend/access/transam/xlogwait.c
@@ -526,9 +526,10 @@ WaitForLSN(WaitLSNType lsnType, XLogRecPtr targetLSN, int64 timeout)
 	}
 
 	/*
-	 * Delete our process from the shared memory heap.  We might already be
-	 * deleted by the startup process.  The 'inHeap' flags prevents us from
-	 * the double deletion.
+	 * A progress waker, such as the startup process during WAL replay, may
+	 * already have removed this waiter through WaitLSNWakeup() before setting
+	 * its latch.  The inHeap flag makes this cleanup safe whether or not the
+	 * entry remains in the heap.
 	 */
 	deleteLSNWaiter(lsnType);
 
-- 
2.51.0

