From 6b669f9ebc71980851ae7ce5ec8119e0bfa9df02 Mon Sep 17 00:00:00 2001
From: Dave Sharpe <davesharpe13@gmail.com>
Date: Tue, 24 Mar 2020 19:58:56 -0400
Subject: [PATCH] Fix CommitTransactionCommand() to CallXactCallbacks() in
 TBLOCK_ABORT_END

---
 src/backend/access/transam/xact.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index e3c60f23cd..b745007102 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -2973,10 +2973,15 @@ CommitTransactionCommand(void)
 
 			/*
 			 * Here we were in an aborted transaction block and we just got
-			 * the ROLLBACK command from the user, so clean up the
+			 * the ROLLBACK command from the user, so first return blockState
+			 * to TBLOCK_ABORT in case of callXactCallbacks() failure, run any
+			 * callback and restore blockState on success. Now clean up the
 			 * already-aborted transaction and return to the idle state.
 			 */
 		case TBLOCK_ABORT_END:
+			s->blockState = TBLOCK_ABORT;
+			CallXactCallbacks(XACT_EVENT_ABORT);
+			s->blockState = TBLOCK_ABORT_END;
 			CleanupTransaction();
 			s->blockState = TBLOCK_DEFAULT;
 			if (s->chain)
-- 
2.16.2

