Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h8TWR-0002xo-H5 for pgsql-bugs@arkaria.postgresql.org; Mon, 25 Mar 2019 17:36:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h8TWP-0005WD-Qh for pgsql-bugs@arkaria.postgresql.org; Mon, 25 Mar 2019 17:36:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h8TWP-0005W6-KO for pgsql-bugs@lists.postgresql.org; Mon, 25 Mar 2019 17:36:29 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h8TWI-0004Tc-E6 for pgsql-bugs@lists.postgresql.org; Mon, 25 Mar 2019 17:36:29 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x2PHaEVS020460; Mon, 25 Mar 2019 13:36:14 -0400 From: Tom Lane To: Peter Eisentraut cc: julian.schauder@gmx.de, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15703: Segfault in cancelled CALL-Statements In-reply-to: <8678.1553097373@sss.pgh.pa.us> References: <15703-c12c5bc0ea34ba26@postgresql.org> <8678.1553097373@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Wed, 20 Mar 2019 11:56:13 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <20458.1553535374.1@sss.pgh.pa.us> Date: Mon, 25 Mar 2019 13:36:14 -0400 Message-ID: <20459.1553535374@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I wrote: > I find HoldPinnedPortals suspicious in another way: is it really > OK for it to mark *all* pinned portals as auto-held? What if we're > in a nest of procedures run by different PLs (of which only the > innermost will have any idea we're committing)? After taking another look at this, I'm convinced that it's flat out broken. It cannot be up to individual PLs to decide whether or not to call HoldPinnedPortals before issuing a commit. If a PL that needs that calls (a function belonging to) some other PL that thinks it doesn't need that, and the second PL issues a commit or rollback, we'll have a failure for whatever portal(s) the first PL left pinned. I think, therefore, that we should get rid of HoldPinnedPortals and just assign the responsibility for holding pinned portals to the normal code paths, probably PreCommit_Portals and AtAbort_Portals. Another issue in this area is whether it's really safe to hold a portal during transaction abort at all. I'm inclined to think that it is not. HoldPortal can call arbitrary user code, and the idea that we'll let that happen during an already-failed transaction seems borderline insane from here. However, I'm not very sure what we can do instead. As things stand right now, the calls of HoldPinnedPortals from places like exec_stmt_rollback are safe in this sense, because we haven't yet started to abort the current transaction. However, that just raises the question of why we need those calls at all. If a transaction abort happens due to some kind of error, we aren't going to do any pinned-portal holding, so why should we need it in exec_stmt_rollback? Maybe the rule needs to be "we'll do HoldPinnedPortals in SPI_rollback, but not if you reach transaction abort via an actual error". Seems a bit weird though. Thoughts? regards, tom lane