aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-05-28 23:57:27 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2012-05-28 23:57:27 -0400
commit66cad2d7b4e08bcad61507d50b9640b814c16b34 (patch)
tree07e35cbdf1f7ad4759734ae1637f07d694f94ef9
parent35cc2be6f41f1cb0df2a75dc82fe7ee62343f69b (diff)
downloadpostgresql-66cad2d7b4e08bcad61507d50b9640b814c16b34.tar.gz
postgresql-66cad2d7b4e08bcad61507d50b9640b814c16b34.zip
Teach AbortOutOfAnyTransaction to clean up partially-started transactions.
AbortOutOfAnyTransaction failed to do anything if the state it saw on entry corresponded to failing partway through StartTransaction. I fixed AbortCurrentTransaction to cope with that case way back in commit 60b2444cc3ba037630c9b940c3c9ef01b954b87b, but evidently overlooked that AbortOutOfAnyTransaction should do likewise. Back-patch to all supported branches. It's not clear that this omission has any more-than-cosmetic consequences, but it's also not clear that it doesn't, so back-patching seems the least risky choice.
-rw-r--r--src/backend/access/transam/xact.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index f2c5c169271..e33e5a912c8 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -3574,7 +3574,24 @@ AbortOutOfAnyTransaction(void)
switch (s->blockState)
{
case TBLOCK_DEFAULT:
- /* Not in a transaction, do nothing */
+ if (s->state == TRANS_DEFAULT)
+ {
+ /* Not in a transaction, do nothing */
+ }
+ else
+ {
+ /*
+ * We can get here after an error during transaction start
+ * (state will be TRANS_START). Need to clean up the
+ * incompletely started transaction. First, adjust the
+ * low-level state to suppress warning message from
+ * AbortTransaction.
+ */
+ if (s->state == TRANS_START)
+ s->state = TRANS_INPROGRESS;
+ AbortTransaction();
+ CleanupTransaction();
+ }
break;
case TBLOCK_STARTED:
case TBLOCK_BEGIN: