From 6374a096e235af93e1d5ce44a904f80e8f24ae24 Mon Sep 17 00:00:00 2001
From: Masahiko Sawada <sawada.mshk@gmail.com>
Date: Mon, 15 Aug 2022 12:35:02 +0900
Subject: [PATCH v2] Add CHECK_FOR_INTERRUPTS in logical decoding's processing
 changes loop.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Add a CHECK_FOR_INTERRUPTS() call in the main loop of processing
logical changes to make the logical decoding responsive to cancellations,
especially while the plugin skipping all changes.

Per bug #17580 reproted from 巨鲸 and Andrey Borodin. Backpatch to all
supported branches.

Author: Masahiko Sawada
Reviwed-by: Amit Kapila
Discussion: https://postgr.es/m/17580-849c1d5b6d7eb422@postgresql.org
Discussion: https://postgr.es/m/B319ECD6-9A28-4CDF-A8F4-3591E0BF2369@yandex-team.ru
Backpatch-through: 10
---
 src/backend/replication/logical/reorderbuffer.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c
index ef8c2ea6df..368f60159d 100644
--- a/src/backend/replication/logical/reorderbuffer.c
+++ b/src/backend/replication/logical/reorderbuffer.c
@@ -1577,6 +1577,8 @@ ReorderBufferCommit(ReorderBuffer *rb, TransactionId xid,
 			Relation	relation = NULL;
 			Oid			reloid;
 
+			CHECK_FOR_INTERRUPTS();
+
 			switch (change->action)
 			{
 				case REORDER_BUFFER_CHANGE_INTERNAL_SPEC_CONFIRM:
-- 
2.24.3 (Apple Git-128)

