Subject: [PATCH] Check interrupts while draining received WAL

The inner receive loop in WalReceiverMain() drains all immediately
available WAL without checking interrupts.  If the receiver writes WAL
more slowly than the sender supplies it, the loop can postpone processing
SIGTERM.  This can delay SIGTERM-driven receiver termination during server
shutdown, promotion, or reconfiguration.  When termination is requested
by startup, that process can remain in ShutdownWalRcv() waiting for the
receiver to exit.

Check interrupts on each iteration of the inner loop so that shutdown
requests are processed even when WAL is continuously available.

---
 src/backend/replication/walreceiver.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c
index 11b9a12c52c..ef9f8718834 100644
--- a/src/backend/replication/walreceiver.c
+++ b/src/backend/replication/walreceiver.c
@@ -549,6 +549,8 @@ WalReceiverMain(const void *startup_data, size_t startup_data_len)
 					 */
 					for (;;)
 					{
+						CHECK_FOR_INTERRUPTS();
+
 						if (len > 0)
 						{
 							/*
