Re: 048_vacuum_horizon_floor.pl hangs due to wakeup lost inside LockBufferForCleanup - Mailing list pgsql-hackers

From Melanie Plageman
Subject Re: 048_vacuum_horizon_floor.pl hangs due to wakeup lost inside LockBufferForCleanup
Date
Msg-id CAAKRu_b6C_VYoopvDxKogMM148o1E7xQSte1rSu6v58RbhzedA@mail.gmail.com
Whole thread
In response to Re: 048_vacuum_horizon_floor.pl hangs due to wakeup lost inside LockBufferForCleanup  (Xuneng Zhou <xunengzhou@gmail.com>)
Responses Re: 048_vacuum_horizon_floor.pl hangs due to wakeup lost inside LockBufferForCleanup
List pgsql-hackers
On Mon, Jun 22, 2026 at 4:14 AM Xuneng Zhou <xunengzhou@gmail.com> wrote:
>
> The direct regression appears to be 5310fac6e0f. It allows this interleaving:
>
> W: LockBufferForCleanup() holds buffer header lock
> W: observes refcount > 1
> P: releases the last competing pin with atomic fetch_sub
> P: old state does not contain BM_PIN_COUNT_WAITER, so no wakeup
> W: publishes BM_PIN_COUNT_WAITER
> W: sleeps in ProcWaitForSignal()
>
> At this point the condition W wanted is already true: refcount is 1,
> meaning only W's own pin remains. So W could sleep indefinitely as no
> future unpin to wake it.
>
> We can fix this with the state returned by UnlockBufHdrExt() when
> publishing BM_PIN_COUNT_WAITER. If the wait refcount is 1, do not
> enter the wait path. Instead, fall through to the existing waiter-bit
> cleanup and retry the loop to acquire the cleanup lock normally. The
> reproducer test passed after applying the patch.

Thanks for investigating!
Does the reproducer pass prior to 5310fac6e0f?

- Melanie



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: psql: Fix CREATE SCHEMA scanning of nested routine bodies
Next
From: Vitaly Davydov
Date:
Subject: Re: Deadlock detector fails to activate on a hot standby replica