Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mVJVc-0006LG-AP for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Sep 2021 20:15:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mVJVa-0001bI-C9 for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Sep 2021 20:15:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mVJVa-0001b9-3s for pgsql-hackers@lists.postgresql.org; Tue, 28 Sep 2021 20:15:22 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mVJVT-0005mn-D5 for pgsql-hackers@lists.postgresql.org; Tue, 28 Sep 2021 20:15:20 +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 18SKFE7N2899370; Tue, 28 Sep 2021 16:15:14 -0400 From: Tom Lane To: Christophe Pettus cc: pgsql-hackers@lists.postgresql.org Subject: Re: statement_timeout vs DECLARE CURSOR In-reply-to: <2873020.1632859041@sss.pgh.pa.us> References: <2767393.1632771639@sss.pgh.pa.us> <2873020.1632859041@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Tue, 28 Sep 2021 15:57:21 -0400" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <2899345.1632860097.0@sss.pgh.pa.us> Date: Tue, 28 Sep 2021 16:15:14 -0400 Message-ID: <2899369.1632860114@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2899345.1632860097.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable [ redirect to -hackers ] I wrote: >> Christophe Pettus writes: >>> A bit more poking revealed the reason: The ON HOLD cursor's query is e= xecuted at commit time (which is, logically, not interruptible), but that'= s all wrapped in the single statement outside of a transaction. >> Hmm ... seems like a bit of a UX failure. I wonder why we don't persis= t >> such cursors before we get into the uninterruptible part of COMMIT. > Oh, I see the issue. It's not that that part of COMMIT isn't > interruptible; you can control-C out of it just fine. The problem > is that finish_xact_command() disarms the statement timeout before > starting CommitTransactionCommand at all. > We could imagine pushing the responsibility for that down into > xact.c, allowing it to happen after CommitTransaction has finished > running user-defined code. But it seems like a bit of a mess > because there are so many other code paths there. Not sure how > to avoid future bugs-of-omission. Actually ... maybe it needn't be any harder than the attached? This makes it possible for a statement timeout interrupt to occur anytime during CommitTransactionCommand, but I think CommitTransactionCommand had better be able to protect itself against that anyway, for a couple of reasons: 1. It's not significantly different from a query-cancel interrupt, which surely could arrive during that window. 2. COMMIT-within-procedures already exposes us to statement timeout during COMMIT. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="include-commit-processing-in-statement-timeout.patch"; charset="us-ascii" Content-ID: <2899345.1632860097.2@sss.pgh.pa.us> Content-Description: include-commit-processing-in-statement-timeout.patch diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 0775abe35d..9ec96f2453 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -2713,9 +2713,6 @@ start_xact_command(void) static void finish_xact_command(void) { - /* cancel active statement timeout after each command */ - disable_statement_timeout(); - if (xact_started) { CommitTransactionCommand(); @@ -2733,6 +2730,9 @@ finish_xact_command(void) xact_started = false; } + + /* cancel active statement timeout after each command */ + disable_statement_timeout(); } ------- =_aaaaaaaaaa0--