pgsql: Avoid delaying WAL receiver shutdown while draining WAL

From: Fujii Masao <fujii(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Avoid delaying WAL receiver shutdown while draining WAL
Date: 2026-11-19 04:31:22
Message-ID: E1xTtnt-00000000KvV-2dux@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Avoid delaying WAL receiver shutdown while draining WAL

Standby shutdown, promotion, and changes to replication connection
settings could be delayed while the WAL receiver was continuously
receiving WAL.

The inner receive loop in WalReceiverMain() processed all immediately
available messages without checking interrupts. If WAL arrived faster
than the receiver could write it, the receiver could remain in this
loop with SIGTERM pending, leaving the startup process waiting for it
to exit.

Fix this by checking interrupts on each iteration of the inner loop so
that pending shutdown requests are handled even when more WAL is
available.

Backpatch to all supported versions.

Reported-by: Andres Freund <andres(at)anarazel(dot)de>
Author: Nitin Jadhav <nitinjadhavpostgres(at)gmail(dot)com>
Reviewed-by: Joao Rito <joaovictor(dot)rito(at)gmail(dot)com>
Reviewed-by: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Discussion: https://postgr.es/m/20210511022755.wcb5h4czadxsgewt@alap3.anarazel.de
Discussion: https://postgr.es/m/CAMm1aWY-bps8VPCdyTTZo6NZicSRrq0kBArzjKTZoKHdN_wqOA@mail.gmail.com
Backpatch-through: 15

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/f0f3a041837c706e3db8a5bcd0feb93f518fed00

Modified Files
--------------
src/backend/replication/walreceiver.c | 2 ++
1 file changed, 2 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Fujii Masao 2026-11-19 04:31:32 pgsql: Avoid delaying WAL receiver shutdown while draining WAL
Previous Message Fujii Masao 2026-11-19 04:31:13 pgsql: Avoid delaying WAL receiver shutdown while draining WAL