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 1w4ydA-002lX0-2v for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Mar 2026 10:05:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w4yd9-005qLl-1L for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Mar 2026 10:04:59 +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 1w4yd8-005qLd-1N for pgsql-hackers@lists.postgresql.org; Tue, 24 Mar 2026 10:04:59 +0000 Received: from m16.mail.163.com ([220.197.31.2]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w4yd2-00000000ltU-1wQM for pgsql-hackers@lists.postgresql.org; Tue, 24 Mar 2026 10:04:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version: Content-Type; bh=e6e/napHGtDt49Nu+s9mu3KeiA3awAvMuB9WRkHemXk=; b=eRzJrFqVLRLqH07WcWZgui6Jjwi02f4stSSB3uAPB8afROqtS9Tb7bgT0a2C1N L7TOCYq6C4VcyUJJOB2K7ovhOa4obCqjqFbom9pJ78bEgyAYxoae/7Nr8dvyz+zW tEag2PnBSrnqwzIf3+Qb7j6seo+l6wrlTAeT1kTDQQJM4= Received: from andy-coding (unknown []) by gzga-smtp-mtada-g1-2 (Coremail) with SMTP id _____wA3we67YcJp8VmBBA--.42354S3; Tue, 24 Mar 2026 18:04:44 +0800 (CST) From: Andy Fan To: PostgreSQL Hackers Subject: raise ERROR between EndPrepare and PostPrepare_Locks causes ROLLBACK 2pc PAINC User-Agent: mu4e 1.14.0-pre2; emacs 30.2 Date: Tue, 24 Mar 2026 18:04:43 +0800 Message-ID: <87341p7dc4.fsf@163.com> MIME-Version: 1.0 Content-Type: text/plain X-CM-TRANSID: _____wA3we67YcJp8VmBBA--.42354S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7Aw4DKFW3KF17XF4rKFykKrg_yoW8Jw15pr 93GrsxArWDGFyIvwsruan7XryfA34kJr45J398XF9xCa13u34Fvrs5KFyq9a43KryIyw42 gw1UXFZ2va98AaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zR4SotUUUUU= X-Originating-IP: [101.227.46.165] X-CM-SenderInfo: x2klx3xlid0iqsrtqiywtou0bp/xtbC-xyS5WnCYbwg6wAA3p List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, With the following hack in PrepareTransaction: @@ -2697,6 +2697,8 @@ PrepareTransaction(void) */ EndPrepare(gxact); + elog(ERROR, "some error"); + /* * Now we clean up backend-internal state and release internal resources. */ Then we can do the following test: CREATE TABLE t(a int); begin; insert into t values(1); prepare transaction 'foo'; ERROR: some error. // before the lock transfer rollback prepared 'foo'; PANIC: failed to re-find shared lock object // because lock is released when ERROR. One of the methods in my mind is to delay the END_CRIT_SECTION until PostPrepare_Locks is finished, then the above case would become: (1) ERROR (2) Since CRIT_SECTION, error become to PAINC. (3) client get PAINC and know the prepare failure. (4). server does crash-recovery and the [2pc is recovered] (even client has get error). (5). We (as postgresql developer) should expected 2pc coordinator to run "rollback prepared foo" anyway even the prepared failure and handle the case where 'foo' doesn't exist. I don't think it is a good solution because the mismatch between (3) and (4). and the error handle in step (5). This is not a real case to me, I just run into this with a fault-injection testing framework. So after all is this something which deserves a fix? -- Best Regards Andy Fan