Re: Deadlock detector fails to activate on a hot standby replica

From: Vitaly Davydov <vitprof(at)gmail(dot)com>
To: JoongHyuk Shin <sjh910805(at)gmail(dot)com>, Xuneng Zhou <xunengzhou(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org, Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Subject: Re: Deadlock detector fails to activate on a hot standby replica
Date: 2026-08-31 16:18:14
Message-ID: 7e4f2244-4fd8-4f30-9f61-d1087e4b3292@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi JH Shin,

> I think PinCountWaiterCheckReadyForCleanup() has a window between
> checking the refcount and setting BM_PIN_COUNT_WAITER. On the master
> branch, UnpinBufferNoOwner() drops pins without taking the header
> lock, so the last other pin can go away in that window and the
> wakeup is lost until the deadlock or standby-limit timeout fires.
> This looks like the same race that commit 8d85cb889a3 fixed in
> LockBufferForCleanup(), and the same fix should work here. After
> publishing the flag, recheck the refcount, and if only our own pin
> remains, clear the flag and return true.

Agree, thank you.

I made new changes in two commits. In the first commit coming from v7 patch
I modified RegisterPinCountWaiter() function to recheck the refcount as
explained by you. In the second commit I've replaced the duplicate code in
LockBufferForCleanup to register pincount waiter with the call of
RegisterPinCountWaiter(). The second commit is optional but it fits well
with
the current changes.

The patch was rebased to the actual master branch.

P.S. I replaced my old address v(dot)davydov(at)postgrespro(dot)ru in commits with
my personal email vitprof(at)gmail(dot)com that suits better for me.

With best regards,
Vitaly Davydov
vitprof(at)gmail(dot)com (aka v(dot)davydov(at)postgrespro(dot)ru)
vitcpp(at)mail(dot)ru

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Vitaly Davydov 2026-08-31 16:27:37 Re: Deadlock detector fails to activate on a hot standby replica
Previous Message Bharath Rupireddy 2026-08-31 16:11:39 Re: REPACK (CONCURRENTLY) fails with wrong error for materialized views