PANIC :Call AbortTransaction when transaction id is no normal

From: Thunder <thunder1(at)126(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: PANIC :Call AbortTransaction when transaction id is no normal
Date: 2019-05-13 04:45:25
Message-ID: 3850b11a.5121.16aaf827e4a.Coremail.thunder1@126.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello,

The process crashed when running in bootstrap mode and received signal to shutdown.

From the call stack we can see that the transaction id is 1, which is BootstrapTransactionId.

During TransactionLogFetch function, which fetch commit status of specified transaction id, it will return COMITTED when transcation id is BootstrapTransactionId.

Then it will crash because we cannot abort transaction while it was already committed.

(gdb) bt
#0 0x00007f4598f02617 in raise () from /lib64/libc.so.6
#1 0x00007f4598f03d08 in abort () from /lib64/libc.so.6
#2 0x000000000106001d in errfinish (dummy=0) at elog.c:564
#3 0x0000000001064788 in elog_finish (elevel=22, fmt=0x1190408 "cannot abort transaction %u, it was already committed") at elog.c:1385
#4 0x0000000000633e5a in RecordTransactionAbort (isSubXact=false) at xact.c:1584
#5 0x00000000006361fa in AbortTransaction () at xact.c:2614
#6 0x000000000063a5b9 in AbortOutOfAnyTransaction () at xact.c:4423
#7 0x000000000108f417 in ShutdownPostgres (code=1, arg=0) at postinit.c:1221
#8 0x0000000000d3554a in shmem_exit (code=1) at ipc.c:239
#9 0x0000000000d35395 in proc_exit_prepare (code=1) at ipc.c:194
#10 0x0000000000d352bb in proc_exit (code=1) at ipc.c:107
#11 0x000000000105ffbb in errfinish (dummy=0) at elog.c:550
#12 0x0000000000d9a020 in ProcessInterrupts () at postgres.c:3019
#13 0x00000000005489aa in heapgetpage (scan=0x34895f0, page=1) at heapam.c:384
#14 0x000000000054c48d in heapgettup_pagemode (scan=0x34895f0, dir=ForwardScanDirection, nkeys=1, key=0x33cf150) at heapam.c:1052
#15 0x000000000054e3e0 in heap_getnext (scan=0x34895f0, direction=ForwardScanDirection) at heapam.c:1850
#16 0x00000000006fe364 in index_update_stats (rel=0x7f459b770030, hasindex=true, reltuples=0) at index.c:2167
#17 0x00000000006ff40b in index_build (heapRelation=0x7f459b770030, indexRelation=0x7f459b704ca8, indexInfo=0x345c008, isprimary=false, isreindex=false, parallel=false) at index.c:2398
#18 0x00000000006e3ae3 in build_indices () at bootstrap.c:1112
#19 0x00000000006dbc8b in boot_yyparse () at bootparse.y:399
#20 0x00000000006e17f4 in BootstrapModeMain () at bootstrap.c:516
#21 0x00000000006e1578 in AuxiliaryProcessMain (argc=6, argv=0x33299b8) at bootstrap.c:436
#22 0x0000000000aab0be in main (argc=7, argv=0x33299b0) at main.c:220
(gdb) f 4
#4 0x0000000000633e5a in RecordTransactionAbort (isSubXact=false) at xact.c:1584
1584 elog(PANIC, "cannot abort transaction %u, it was already committed",
(gdb) p xid
$4 = 1

I try to fix this issue and check whether it's normal transaction id before we do abort.

diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index 20feeec327..dbf2bf567a 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -4504,8 +4504,13 @@ RollbackAndReleaseCurrentSubTransaction(void)
void
AbortOutOfAnyTransaction(void)
{
+ TransactionId xid = GetCurrentTransactionIdIfAny();
TransactionState s = CurrentTransactionState;

+ /* Check to see if the transaction ID is a permanent one because we cannot abort it */
+ if (!TransactionIdIsNormal(xid))
+ return;
+
/* Ensure we're not running in a doomed memory context */
AtAbort_Memory();

Can we fix in this way?

Thanks

Ray

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Smith, Peter 2019-05-13 05:09:34 RE: [Proposal] Table-level Transparent Data Encryption (TDE) and Key Management Service (KMS)
Previous Message Bruce Momjian 2019-05-13 03:53:45 Re: PG 12 draft release notes