Fix lost wakeups in logical WAL senders Logical WAL senders could sleep even when WAL was available for decoding, delaying logical replication until another event woke them. When synchronous logical replication is configured, this could also delay commits waiting for acknowledgment from the subscriber.
Commit bc971f4025c changed WAL sender wakeups to use condition variables, which notify only senders already on the waitlist. However, WalSndWaitForWal() checks the flush position on a primary, or the replay position on a standby, before WalSndWait() joins the waitlist. If the required WAL becomes available between these two steps, the wakeup can be missed, leaving the sender asleep despite having enough WAL to continue decoding. Fix this by passing the required WAL position to WalSndWait() and rechecking the flush or replay position after joining the waitlist. If enough WAL is available, return to WalSndWaitForWal() to reevaluate its conditions, including any need to wait for standby confirmation. This allows decoding to proceed without waiting for another wakeup when the required WAL became available before waitlist registration, avoiding the resulting replication and synchronous commit delays. Backpatch to v16, where commit bc971f4025c introduced the condition-variable wakeup mechanism. Author: Fujii Masao <[email protected]> Reviewed-by: Xuneng Zhou <[email protected]> Discussion: https://postgr.es/m/mvx5bs7q.33b99c32-67d8-4373-8611-7a8250fb2...@we.are.superhuman.com Backpatch-through: 16 Branch ------ REL_16_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/2161e1732f5a4113f0b21e2dbc9ed0b86fb3e07e Modified Files -------------- src/backend/replication/walsender.c | 42 ++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-)
