Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x4vTF-007VIQ-2n for pgsql-hackers@arkaria.postgresql.org; Fri, 11 Sep 2026 07:14:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x4vTE-00CfSK-1t for pgsql-hackers@arkaria.postgresql.org; Fri, 11 Sep 2026 07:14:48 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x4vTE-00CfRZ-02 for pgsql-hackers@lists.postgresql.org; Fri, 11 Sep 2026 07:14:48 +0000 Received: from mail.postgrespro.ru ([93.174.132.70]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x4vT9-000000055nM-2Bc7 for pgsql-hackers@postgresql.org; Fri, 11 Sep 2026 07:14:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1789110879; bh=3jp1L3wQN+nqWYtZ2bvMlDFEmS3ccpm6W7PVFDKvyxM=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=UUh+JlDYwNQrHhpfE6lKZ+T6/OLwQJtGFKjZsFR9rhTqYYGFQ6GKM9gto5Q/2VOyr iCW1b/q+nfIsnsCoDKwW18Ryfzij8Zh4EdM/vebPRq8vOvCdnRG1Joz1h7Zb6X0NjA NwIjp3c/VtToorYapFBfhwPJ1kxqiblUsOQx38HzDwGdOqbuqxjDtbaH0LTFNBGt82 UW2CQaI/NPIzVOp+l7nJRNHNxdSi8Us1r1jYWRefpj3cb6S7TcyY813++c9vFdQQ+M qc4OLbtf1dC7L3s6Lu0m8WsC9tHF/g9ek+Q2NptB42OAE4ZTexmdTyEwn+EJSbSCbc I7D+t2nBnaNoA== Received: from [172.30.49.142] (debian11-template.l.postgrespro.ru [192.168.2.254]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: m.melnikov@postgrespro.ru) by mail.postgrespro.ru (Postfix/465) with ESMTPSA id 41CE46397B; Fri, 11 Sep 2026 10:14:39 +0300 (MSK) Content-Type: multipart/alternative; boundary="------------EHJYbWv7G6W0YJHnsW8ejezc" Message-ID: <7a6305be-a1fc-43f9-be19-b1442e1c4b92@postgrespro.ru> Date: Fri, 11 Sep 2026 10:14:39 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Race between prepared transaction commit and checkpointer To: Osama Abdul Qader Cc: PostgreSQL Hackers References: <6110933b-f07c-4600-8c51-be46e8ec549d@postgrespro.ru> Content-Language: en-US From: "Maksim.Melnikov" In-Reply-To: X-KSMG-AntiPhishing: NotDetected, bases: 2026/09/11 06:55:00 X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 3.0.0.9059, bases: 2026/09/11 06:49:00 #28572820 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------EHJYbWv7G6W0YJHnsW8ejezc Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Thanks, I found one more suspicious place, pls take a look at checkpointer  CheckPointTwoPhase method, I am little bit suprised that we acquire LW_SHARED lock here, because with this lock we are changing gxact members, if some concurrent proc read this one with LW_SHARED, it can get stale values. I am not sure but for example it can be LookupGXact. Anyway, if I am mistaken, sorry for noise. Best regards, Maksim Melnikov On 9/10/26 21:12, Osama Abdul Qader wrote: > Hi Maskim, > > Sure I'll look into it. I'll reproduce the bug in my machine amd I'll > review the patches attached in this email. > > I'll let you know once I reproduce the issue in my machine and review > the patch. > > With regards, > Osama Abdul Qader > > On Thu, 10 Sept, 2026, 10:20 pm Maksim.Melnikov, > wrote: > > Hi, hackers! > > I think I found an issue in two-phase commit code, I've attached > patch > with reproducing, pls take a look(master rev 9f4bd91a196). > I've got coredump with backtrace like this > > #0  __pthread_kill_implementation (no_tid=0, signo=6, > threadid=) at ./nptl/pthread_kill.c:44 > #1  __pthread_kill_internal (signo=6, threadid=) at > ./nptl/pthread_kill.c:78 > #2  __GI___pthread_kill (threadid=, > signo=signo@entry=6) > at ./nptl/pthread_kill.c:89 > #3  0x00007de7ef24527e in __GI_raise (sig=sig@entry=6) at > ../sysdeps/posix/raise.c:26 > #4  0x00007de7ef2288ff in __GI_abort () at ./stdlib/abort.c:79 > #5  0x0000610d848485bb in ExceptionalCondition > (conditionName=0x610d84910812 "XLogRecPtrIsValid(RecPtr)", > fileName=0x610d849107c2 "xlogreader.c", lineNumber=240) at assert.c:65 > #6  0x0000610d840b0926 in XLogBeginRead (state=0x610d948b06a8, > RecPtr=0) > at xlogreader.c:240 > #7  0x0000610d8408ba9a in XlogReadTwoPhaseData (lsn=0, > buf=0x7fff8c941248, len=0x0) at twophase.c:1437 > #8  0x0000610d8408be05 in FinishPreparedTransaction > (gid=0x610d947e6698 > "test_transaction", isCommit=true) at twophase.c:1544 > #9  0x0000610d8462b70e in standard_ProcessUtility > (pstmt=0x610d947e6798, > queryString=0x610d947e5cb0 "COMMIT PREPARED 'test_transaction';", > readOnlyTree=false, >      context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0, > dest=0x610d947e6b58, qc=0x7fff8c941730) at utility.c:655 > #10 0x0000610d8462ade6 in ProcessUtility (pstmt=0x610d947e6798, > queryString=0x610d947e5cb0 "COMMIT PREPARED 'test_transaction';", > readOnlyTree=false, >      context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0, > dest=0x610d947e6b58, qc=0x7fff8c941730) at utility.c:525 > #11 0x0000610d846293ee in PortalRunUtility (portal=0x610d94864a20, > pstmt=0x610d947e6798, isTopLevel=true, setHoldSnapshot=false, > dest=0x610d947e6b58, qc=0x7fff8c941730) >      at pquery.c:1149 > #12 0x0000610d84629668 in PortalRunMulti (portal=0x610d94864a20, > isTopLevel=true, setHoldSnapshot=false, dest=0x610d947e6b58, > altdest=0x610d947e6b58, qc=0x7fff8c941730) >      at pquery.c:1307 > #13 0x0000610d84628ac0 in PortalRun (portal=0x610d94864a20, > count=9223372036854775807, isTopLevel=true, dest=0x610d947e6b58, > altdest=0x610d947e6b58, qc=0x7fff8c941730) at pquery.c:784 > #14 0x0000610d84620b10 in exec_simple_query > (query_string=0x610d947e5cb0 > "COMMIT PREPARED 'test_transaction';") at postgres.c:1297 > .... > > > It seems we have race between prepared transaction commit and > checkpointer and it is old problem. We need TwoPhaseStateLock wrap > the > reading state file in FinishPreparedTransaction code, the draft > patch is > attached too, hope it will be helpful. > > > Best regards, > Maksim Melnikov > --------------EHJYbWv7G6W0YJHnsW8ejezc Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

Thanks, I found one more suspicious place, pls take a look at checkpointer  CheckPointTwoPhase method, I am little bit suprised that we acquire LW_SHARED lock here, because with this lock

we are changing gxact members, if some concurrent proc read this one with LW_SHARED, it can get stale values. I am not sure but for example it can be LookupGXact.

Anyway, if I am mistaken, sorry for noise.

Best regards,

Maksim Melnikov

On 9/10/26 21:12, Osama Abdul Qader wrote:
Hi Maskim,

Sure I'll look into it. I'll reproduce the bug in my machine amd I'll review the patches attached in this email.

I'll let you know once I reproduce the issue in my machine and review the patch.

With regards,
Osama Abdul Qader

On Thu, 10 Sept, 2026, 10:20 pm Maksim.Melnikov, <m.melnikov@postgrespro.ru> wrote:
Hi, hackers!

I think I found an issue in two-phase commit code, I've attached patch
with reproducing, pls take a look(master rev 9f4bd91a196).
I've got coredump with backtrace like this

#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@entry=6)
at ./nptl/pthread_kill.c:89
#3  0x00007de7ef24527e in __GI_raise (sig=sig@entry=6) at
../sysdeps/posix/raise.c:26
#4  0x00007de7ef2288ff in __GI_abort () at ./stdlib/abort.c:79
#5  0x0000610d848485bb in ExceptionalCondition
(conditionName=0x610d84910812 "XLogRecPtrIsValid(RecPtr)",
fileName=0x610d849107c2 "xlogreader.c", lineNumber=240) at assert.c:65
#6  0x0000610d840b0926 in XLogBeginRead (state=0x610d948b06a8, RecPtr=0)
at xlogreader.c:240
#7  0x0000610d8408ba9a in XlogReadTwoPhaseData (lsn=0,
buf=0x7fff8c941248, len=0x0) at twophase.c:1437
#8  0x0000610d8408be05 in FinishPreparedTransaction (gid=0x610d947e6698
"test_transaction", isCommit=true) at twophase.c:1544
#9  0x0000610d8462b70e in standard_ProcessUtility (pstmt=0x610d947e6798,
queryString=0x610d947e5cb0 "COMMIT PREPARED 'test_transaction';",
readOnlyTree=false,
     context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0,
dest=0x610d947e6b58, qc=0x7fff8c941730) at utility.c:655
#10 0x0000610d8462ade6 in ProcessUtility (pstmt=0x610d947e6798,
queryString=0x610d947e5cb0 "COMMIT PREPARED 'test_transaction';",
readOnlyTree=false,
     context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0,
dest=0x610d947e6b58, qc=0x7fff8c941730) at utility.c:525
#11 0x0000610d846293ee in PortalRunUtility (portal=0x610d94864a20,
pstmt=0x610d947e6798, isTopLevel=true, setHoldSnapshot=false,
dest=0x610d947e6b58, qc=0x7fff8c941730)
     at pquery.c:1149
#12 0x0000610d84629668 in PortalRunMulti (portal=0x610d94864a20,
isTopLevel=true, setHoldSnapshot=false, dest=0x610d947e6b58,
altdest=0x610d947e6b58, qc=0x7fff8c941730)
     at pquery.c:1307
#13 0x0000610d84628ac0 in PortalRun (portal=0x610d94864a20,
count=9223372036854775807, isTopLevel=true, dest=0x610d947e6b58,
altdest=0x610d947e6b58, qc=0x7fff8c941730) at pquery.c:784
#14 0x0000610d84620b10 in exec_simple_query (query_string=0x610d947e5cb0
"COMMIT PREPARED 'test_transaction';") at postgres.c:1297
....


It seems we have race between prepared transaction commit and
checkpointer and it is old problem. We need TwoPhaseStateLock wrap the
reading state file in FinishPreparedTransaction code, the draft patch is
attached too, hope it will be helpful.


Best regards,
Maksim Melnikov
--------------EHJYbWv7G6W0YJHnsW8ejezc--