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.94.2) (envelope-from ) id 1rAdPH-007UOB-Im for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Dec 2023 21:56:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rAdPE-006Oa8-GV for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Dec 2023 21:56:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rAdPE-006OZz-6y for pgsql-hackers@lists.postgresql.org; Tue, 05 Dec 2023 21:56:40 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rAdPB-00AHlK-HF for pgsql-hackers@lists.postgresql.org; Tue, 05 Dec 2023 21:56:39 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 3B5LuXTQ976745; Tue, 5 Dec 2023 16:56:33 -0500 From: Tom Lane To: Hao Zhang cc: Andres Freund , pgsql-hackers@lists.postgresql.org Subject: Re: [PATCH] plpython function causes server panic In-reply-to: References: <301509.1701479055@sss.pgh.pa.us> <307441.1701481871@sss.pgh.pa.us> Comments: In-reply-to Hao Zhang message dated "Mon, 04 Dec 2023 17:21:29 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <976743.1701813393.1@sss.pgh.pa.us> Date: Tue, 05 Dec 2023 16:56:33 -0500 Message-ID: <976744.1701813393@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hao Zhang writes: >> The only readily-reachable error case in BeginInternalSubTransaction >> is this specific one about IsInParallelMode, which was added later >> than the original design and evidently with not a lot of thought or >> testing. The comment for it speculates about whether we could get >> rid of it, so I wonder if our thoughts about this ought to go in that >> direction. > IMHO, there are other error reports in the function > BeginInternalSubTransaction(), like Sure, but all the other ones are extremely hard to hit, which is why we didn't bother to worry about them to begin with. If we want to make this more formally bulletproof, my inclination would be to (a) get rid of the IsInParallelMode restriction and then (b) turn the function into a critical section, so that any other error gets treated as a PANIC. Maybe at some point we'd be willing to make a variant of BeginInternalSubTransaction that has a different API and can manage such cases without a PANIC, but that seems far down the road to me, and certainly not something to be back-patched. The main reason for my caution here is that, by catching an error and allowing Python (or Perl, or something else) code to decide what to do next, we are very dependent on that code doing the right thing. This is already a bit of a leap of faith for run-of-the-mill errors. For errors in transaction startup or shutdown, I think it's a bigger leap than I care to make. We're pretty well hosed if we can't make the transaction machinery work, so imagining that we can clean up after such an error and march merrily onwards seems mighty optimistic. regards, tom lane