diff --git a/src/backend/distributed/transaction/transaction_management.c b/src/backend/distributed/transaction/transaction_management.c index 88b820c0e..33faa73d5 100644 --- a/src/backend/distributed/transaction/transaction_management.c +++ b/src/backend/distributed/transaction/transaction_management.c @@ -328,12 +328,17 @@ CoordinatedTransactionCallback(XactEvent event, void *arg) CoordinatedRemoteTransactionsAbort(); } - /* close connections etc. */ - if (CurrentCoordinatedTransactionState != COORD_TRANS_NONE) - { - ResetPlacementConnectionManagement(); - AfterXactConnectionHandling(false); - } + /* + * Close connections etc. Contrary to a successful transaction we reset the + * placement connection management irregardless of state of the statemachine + * as recorded in CurrentCoordinatedTransactionState. + * The hashmaps recording the connection management live a memory context + * higher compared to most of the data referenced in the hashmap. This causes + * use after free errors when the contents are retained due to an error caused + * before the CurrentCoordinatedTransactionState changed. + */ + ResetPlacementConnectionManagement(); + AfterXactConnectionHandling(false); ResetGlobalVariables();