From 54419703be7b0b6c6c1c47b9c1bd709b53b5b895 Mon Sep 17 00:00:00 2001 From: alterego655 <824662526@qq.com> Date: Fri, 24 Jul 2026 16:37:20 +0800 Subject: [PATCH v5 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 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/backend/access/transam/xlogwait.c b/src/backend/access/transam/xlogwait.c index 395ab6b2857..2de9d743f78 100644 --- a/src/backend/access/transam/xlogwait.c +++ b/src/backend/access/transam/xlogwait.c @@ -526,9 +526,13 @@ 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. + * Ensure that we are no longer registered before returning. A progress + * waker, such as the startup process during WAL replay, may already have + * removed the waiter through WaitLSNWakeup() before its latch is set. + * However, the loop can also exit with the waiter still in the heap, such as + * when the target was already reached when it was added or when the wait + * times out. deleteLSNWaiter() uses inHeap to remove it only if it is still + * present. */ deleteLSNWaiter(lsnType); -- 2.51.0