raising errors from Xact leads to assertion failure

From: Kirill Reshke <reshkekirill(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: raising errors from Xact leads to assertion failure
Date: 2026-05-06 16:34:34
Message-ID: CALdSSPiUuha+gr20u-0KxG7od=u0n-WRBUnnVaGoHQJNvjhGbQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi!

I am testing our 2pc tx implementation at the moment, and to do that,
I created a simple auxiliary extension at [0].

My intent is to test what would happened in my system when one of
PostgreSQL shards will error-out during PREPARE TRANSACTION
(practically, this happens from time to time when postgresql is
configured with max_prep_xact = 0)

When I compile it with master (which is
5cdec423193cb99b502816197395637120256f0d for me) and run this SQL, it
leads to assertion failure.

My extension does elog() for the XACT_EVENT_PREPARE event type in
XactCallback. For XACT_EVENT_PRE_PREPARE everything works just fine.

So... My question is, is this illegal to elog () in
XACT_EVENT_PREPARE case, and if yes, is this somehow documented ?

SQL:
reshke=# set twopc_aux_tester.error_on_prepare to true;
SET
reshke=# begin;
BEGIN
reshke=*# prepare transaction 'dz';
ERROR: injected error

```
Continuing.
(gdb)
Program received signal SIGABRT, Aborted.
__pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized
out>) at ./nptl/pthread_kill.c:44
warning: 44 ./nptl/pthread_kill.c: No such file or directory
(gdb) bt
#0 __pthread_kill_implementation (no_tid=0, signo=6,
threadid=<optimized out>) at ./nptl/pthread_kill.c:44
#1 __pthread_kill_internal (signo=6, threadid=<optimized out>) at
./nptl/pthread_kill.c:78
#2 __GI___pthread_kill (threadid=<optimized out>,
signo=signo(at)entry=6) at ./nptl/pthread_kill.c:89
#3 0x00007724a144527e in __GI_raise (sig=sig(at)entry=6) at
../sysdeps/posix/raise.c:26
#4 0x00007724a14288ff in __GI_abort () at ./stdlib/abort.c:79
#5 0x000057429dc7d9cf in ExceptionalCondition
(conditionName=conditionName(at)entry=0x57429dd94bb0
"TransactionIdIsValid(proc->xid)",
fileName=fileName(at)entry=0x57429dd05192 "procarray.c",
lineNumber=lineNumber(at)entry=673) at assert.c:65
#6 0x000057429dae9293 in ProcArrayEndTransaction
(proc=0x77249e689500, latestXid=<optimized out>) at procarray.c:673
#7 0x000057429d7bfb84 in AbortTransaction () at xact.c:3002
#8 0x000057429d7c04f6 in AbortCurrentTransactionInternal () at xact.c:3629
#9 AbortCurrentTransaction () at xact.c:3507
#10 0x000057429db18c48 in PostgresMain (dbname=<optimized out>,
username=<optimized out>) at postgres.c:4539
#11 0x000057429db13333 in BackendMain (startup_data=<optimized out>,
startup_data_len=<optimized out>) at backend_startup.c:124
#12 0x000057429da50ec1 in postmaster_child_launch
(child_type=<optimized out>, child_slot=1,
startup_data=startup_data(at)entry=0x7ffc84fb6d30,
startup_data_len=startup_data_len(at)entry=24,
client_sock=client_sock(at)entry=0x7ffc84fb6d50) at launch_backend.c:268
#13 0x000057429da54b2a in BackendStartup (client_sock=0x7ffc84fb6d50)
at postmaster.c:3627
#14 ServerLoop () at postmaster.c:1728
#15 0x000057429da566f8 in PostmasterMain (argc=argc(at)entry=3,
argv=argv(at)entry=0x5742b27a31a0) at postmaster.c:1415
#16 0x000057429d6fb0ae in main (argc=3, argv=0x5742b27a31a0) at main.c:231
(gdb)

```

[0] https://github.com/pg-sharding/twopc_aux_tester

--
Best regards,
Kirill Reshke

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2026-05-06 16:48:27 Re: Why is_admin_of_role() use ROLERECURSE_MEMBERS rather than ROLERECURSE_PRIVS?
Previous Message Nathan Bossart 2026-05-06 16:13:21 Re: pgindent versus struct members and typedefs