pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Re-register LSN waiters after stale wakeups
2+ messages / 1 participants
[nested] [flat]

* pgsql: Re-register LSN waiters after stale wakeups
@ 2026-08-18 12:02 Alexander Korotkov <akorotkov@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Alexander Korotkov @ 2026-08-18 12:02 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Re-register LSN waiters after stale wakeups

WaitLSNWakeup() removes a waiter from the heap before setting its latch.
If the position that caused the wakeup moves backwards before the waiter
rechecks it, as can happen when WAL streaming restarts, the waiter may
sleep again while no longer registered.  Subsequent WAL progress then
cannot wake it.

When an unmet waiter finds that it is no longer in the heap, add it back
and restart the loop.  Rereading the position after registration also
prevents missing an advance between the previous read and the re-add.

Process interrupts before re-registering rather than after, so that a
wakeup which goes stale again cannot postpone cancellation, however often
it repeats.  As a side effect, a pending cancel now wins over an expired
timeout, which previously reported a timeout instead.

Add deterministic TAP coverage that simulates a stale standby_write
wakeup without advancing the actual write or replay positions.

Author: Xuneng Zhou <xunengzhou@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Discussion: https://postgr.es/m/CABPTF7UtW_cAa%3DQh4RDfKiUqu3pJJE22ai9tbWJVERbeRyssLw%40mail.gmail.com
Backpatch-through: 19

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/70b7e968d5773026ea5105ae7ff23d362bf9723d

Modified Files
--------------
src/backend/access/transam/xlogwait.c              | 37 +++++++-
src/test/modules/Makefile                          |  1 +
src/test/modules/meson.build                       |  1 +
src/test/modules/test_wait_lsn/Makefile            | 21 +++++
src/test/modules/test_wait_lsn/meson.build         | 22 +++++
.../modules/test_wait_lsn/test_wait_lsn--1.0.sql   | 14 +++
src/test/modules/test_wait_lsn/test_wait_lsn.c     | 99 ++++++++++++++++++++++
.../modules/test_wait_lsn/test_wait_lsn.control    |  4 +
src/test/recovery/Makefile                         |  3 +-
src/test/recovery/t/049_wait_for_lsn.pl            | 85 +++++++++++++++++++
10 files changed, 284 insertions(+), 3 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* pgsql: Re-register LSN waiters after stale wakeups
@ 2026-08-18 12:02 Alexander Korotkov <akorotkov@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Alexander Korotkov @ 2026-08-18 12:02 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Re-register LSN waiters after stale wakeups

WaitLSNWakeup() removes a waiter from the heap before setting its latch.
If the position that caused the wakeup moves backwards before the waiter
rechecks it, as can happen when WAL streaming restarts, the waiter may
sleep again while no longer registered.  Subsequent WAL progress then
cannot wake it.

When an unmet waiter finds that it is no longer in the heap, add it back
and restart the loop.  Rereading the position after registration also
prevents missing an advance between the previous read and the re-add.

Process interrupts before re-registering rather than after, so that a
wakeup which goes stale again cannot postpone cancellation, however often
it repeats.  As a side effect, a pending cancel now wins over an expired
timeout, which previously reported a timeout instead.

Add deterministic TAP coverage that simulates a stale standby_write
wakeup without advancing the actual write or replay positions.

Author: Xuneng Zhou <xunengzhou@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Discussion: https://postgr.es/m/CABPTF7UtW_cAa%3DQh4RDfKiUqu3pJJE22ai9tbWJVERbeRyssLw%40mail.gmail.com
Backpatch-through: 19

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/0ec36f4ba325062882eb7a36b8f815e85ff8c123

Modified Files
--------------
src/backend/access/transam/xlogwait.c              | 37 +++++++-
src/test/modules/Makefile                          |  1 +
src/test/modules/meson.build                       |  1 +
src/test/modules/test_wait_lsn/Makefile            | 21 +++++
src/test/modules/test_wait_lsn/meson.build         | 22 +++++
.../modules/test_wait_lsn/test_wait_lsn--1.0.sql   | 14 +++
src/test/modules/test_wait_lsn/test_wait_lsn.c     | 99 ++++++++++++++++++++++
.../modules/test_wait_lsn/test_wait_lsn.control    |  4 +
src/test/recovery/Makefile                         |  3 +-
src/test/recovery/t/049_wait_for_lsn.pl            | 85 +++++++++++++++++++
10 files changed, 284 insertions(+), 3 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2026-08-18 12:02 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-08-18 12:02 pgsql: Re-register LSN waiters after stale wakeups Alexander Korotkov <akorotkov@postgresql.org>
2026-08-18 12:02 pgsql: Re-register LSN waiters after stale wakeups Alexander Korotkov <akorotkov@postgresql.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox