10000 Teach AbortOutOfAnyTransaction to clean up partially-started transact… · jcsston/postgres@73bf9b7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 73bf9b7

Browse files
committed
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 60b2444, 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.
1 parent 785b8d6 commit 73bf9b7

File tree

1 file changed

+18
-1
lines changed
  • src/backend/access/transam

1 file changed

+18
-1
lines changed

src/backend/access/transam/xact.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3748,7 +3748,24 @@ AbortOutOfAnyTransaction(void)
37483748
switch (s->blockState)
37493749
{
37503750
case TBLOCK_DEFAULT:
3751-
/* Not in a transaction, do nothing */
3751+
if (s->state == TRANS_DEFAULT)
3752+
{
3753+
/* Not in a transaction, do nothing */
3754+
}
3755+
else
3756+
{
3757+
/*
3758+
* We can get here after an error during transaction start
3759+
* (state will be TRANS_START). Need to clean up the
3760+
* incompletely started transaction. First, adjust the
3761+
* low-level state to suppress warning message from
3762+
* AbortTransaction.
3763+
*/
3764+
if (s->state == TRANS_START)
3765+
s->state = TRANS_INPROGRESS;
3766+
AbortTransaction();
3767+
CleanupTransaction();
3768+
}
37523769
break;
37533770
case TBLOCK_STARTED:
37543771
case TBLOCK_BEGIN:

0 commit comments

Comments
 (0)
0