Re: Lost walsender wakeup stalls synchronous commits until the standby's next reply (16+)

From: alex(at)alexspeller(dot)com
To: "Fujii Masao" <masao(dot)fujii(at)gmail(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: Lost walsender wakeup stalls synchronous commits until the standby's next reply (16+)
Date: 2026-11-02 21:23:52
Message-ID: mvzqf860.c136778c-c241-48e2-8f45-47e65bbaf370@we.are.superhuman.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Mon, Nov 2, 2026 at 4:05 PM UTC, Fujii Masao < masao(dot)fujii(at)gmail(dot)com > wrote:

> Cascading walsenders also seem to miss wakeups for promotion or

> a timeline switch, even when the flush position has not advanced.

> Is that right? If so, I think we should recheck those conditions after

> joining the waitlist as well.

Yes. At promotion GetStandbyFlushRecPtr() doesn't move, because the end-of-recovery record is inserted, not replayed. That record's XLogFlush() also wakes the walsenders while RecoveryInProgress() is still true, so a cascading walsender is often between XLogSendPhysical() and WalSndWait() when StartupXLOG() calls WalSndWakeup(). The timeline-switch wakeup in ApplyWalRecord() has the same shape.

To check, I promoted a cascading standby (primary -> s1 -> s2, promoting s1) with test-race-delay.patch (200 ms) on s1. On REL_18_STABLE with v1, the walsender slept through the promotion in 39 of 40 rounds and only noticed when something else woke it; s2 was over a second late in 4. With v2 none of 70 rounds were late, and in the 30 I logged the new check caught the promotion every time. On master v1 and v2 looked the same at wal_level = replica, because the ProcSignalBarrier in UpdateLogicalDecodingStatusEndOfRecovery() sets the walsender's latch. At wal_level = logical, v1 was over a second late in 13 of 20 rounds and v2 in none.

> I've attached an updated patch with these checks and a few

> cosmetic changes. Thought?

v2 looks good to me. With assertions on master and REL_16/17/18_STABLE (the PG16 version on 16), the recovery TAP tests pass and the repro has no commit over 100 ms. With test-race-delay.patch (20 ms) on the primary at synchronous_commit = on, master, 16 and 18 each complete about 1,200 commits in 60 s, none over 91 ms.

Thanks,

Alex

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Dmytro Astapov 2026-11-03 01:08:59 Re: BUG #19725: PostgreSQL 18.6: pg_restore read failure with io_uring, not observed with worker
Previous Message Venu K 2026-11-02 16:08:46 Re: BUG #19828: "plan should not reference subplan's variable" with Memoize since f8da64e6