From 4c2bf5d2d6e2a5f03f70dbabac51aa5de0493070 Mon Sep 17 00:00:00 2001 From: Brian Cloutier Date: Wed, 9 May 2018 12:59:48 -0700 Subject: [PATCH] Move call to RemoveIntermediateResultsDirectory Errors thrown in the COMMIT handler will cause Postgres to segfault, there's nothing it can do it abort the transaction by the time that handler is called! RemoveIntermediateResultsDirectory is problematic for two reasons: - It has calls to ereport(ERROR which have been known to trigger - It makes memory allocations which raise ERRORs when they fail Once the COMMIT process has begun we don't use the intermediate results, so it's safe to remove them a little earlier in the process. A failure here will abort the transaction. That's pretty unnecessary, it's not that important that we remove the results, but it's still better than a crash. --- src/backend/distributed/transaction/transaction_management.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend/distributed/transaction/transaction_management.c b/src/backend/distributed/transaction/transaction_management.c index b71694439..7c639bdbb 100644 --- a/src/backend/distributed/transaction/transaction_management.c +++ b/src/backend/distributed/transaction/transaction_management.c @@ -159,7 +159,6 @@ CoordinatedTransactionCallback(XactEvent event, void *arg) * transaction management. Do so before doing other work, so the * callbacks still can perform work if needed. */ - RemoveIntermediateResultsDirectory(); ResetShardPlacementTransactionState(); if (CurrentCoordinatedTransactionState == COORD_TRANS_PREPARED) @@ -256,6 +255,8 @@ CoordinatedTransactionCallback(XactEvent event, void *arg) case XACT_EVENT_PRE_COMMIT: { + RemoveIntermediateResultsDirectory(); + /* nothing further to do if there's no managed remote xacts */ if (CurrentCoordinatedTransactionState == COORD_TRANS_NONE) {