Fix lost wakeups in physical WAL senders
authorFujii Masao <fujii@postgresql.org>
Tue, 3 Nov 2026 01:46:41 +0000 (10:46 +0900)
committerFujii Masao <fujii@postgresql.org>
Tue, 3 Nov 2026 01:46:41 +0000 (10:46 +0900)
commit782d9cf8bf823775efb604300713f6c39a5bfb02
tree26acf8376fefbe887e7dac69056a8d31406536c0
parent45ff0b4a317f14539567a3500eb41ec8b06cde3d
Fix lost wakeups in physical WAL senders

Physical WAL senders could sleep even when flushed WAL was waiting to
be sent, delaying replication and synchronous commits until another
event woke them. In the reported case, commits stalled for about ten
seconds, until the standby sent its next periodic status report.

Commit bc971f4025c changed WAL sender wakeups to use condition
variables, which notify only senders already on the waitlist.
However, XLogSendPhysical() checks the flush position before
WalSndWait() joins the waitlist. If WAL is flushed between these two
steps, the wakeup can be missed, leaving the sender asleep despite
having more WAL to send.

Fix this by rechecking the flush position after joining the waitlist
and returning to the send loop if more WAL is available. For cascading
senders, also check for promotion or a timeline change, which require
the sender to revisit the current timeline even if the flush position
has not advanced.

Backpatch to v16, where commit bc971f4025c introduced the
condition-variable wakeup mechanism.

Author: Alex Speller <alex@alexspeller.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/mvx5bs7q.33b99c32-67d8-4373-8611-7a8250fb2fd3@we.are.superhuman.com
Backpatch-through: 16
src/backend/replication/walsender.c