fix.patch

application/octet-stream

Filename: fix.patch
Type: application/octet-stream
Part: 1
Message: Re: BUG #18055: logical decoding core on AllocateSnapshotBuilder()

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Subject: [Bug] to fix AllocateSnapbuilder core
File+
src/backend/replication/logical/logicalfuncs.c 11 0
From d8c3c6a59593227957ce5deb99fffdb4b47534e8 Mon Sep 17 00:00:00 2001
From: "mohen.lhy"
Date: Fri, 4 Aug 2023 16:52:28 +0800
Subject: [PATCH] [Bug] to fix AllocateSnapbuilder core

---
 src/backend/replication/logical/logicalfuncs.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/backend/replication/logical/logicalfuncs.c b/src/backend/replication/logical/logicalfuncs.c
index 4d355b1f976..1ee9193f105 100644
--- a/src/backend/replication/logical/logicalfuncs.c
+++ b/src/backend/replication/logical/logicalfuncs.c
@@ -374,6 +374,17 @@ pg_logical_slot_get_changes_guts(FunctionCallInfo fcinfo, bool confirm, bool bin
 	}
 	PG_CATCH();
 	{
+		/*
+		 * When an error raised, Clean-up work should be needed.
+		 * Otherwise, residual influence can make a crash,
+		 * such as Assert(NInitialRunningXacts == 0).
+		 */
+
+		/* free context, call shutdown callback */
+		FreeDecodingContext(ctx);
+
+		ReplicationSlotRelease();
+
 		/* clear all timetravel entries */
 		InvalidateSystemCaches();
 
-- 
2.32.0.3.g01195cf9f