pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Christophe Pettus <xof@thebuild.com>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: statement_timeout vs DECLARE CURSOR
Date: Tue, 28 Sep 2021 16:15:14 -0400
Message-ID: <2899369.1632860114@sss.pgh.pa.us> (raw)
In-Reply-To: <2873020.1632859041@sss.pgh.pa.us>
References: <A226617F-F248-4F92-BF62-5CF89EAAA148@thebuild.com>
	<B07C838E-5E08-40DC-89BD-BE6EB9EF8D80@thebuild.com>
	<2767393.1632771639@sss.pgh.pa.us>
	<2873020.1632859041@sss.pgh.pa.us>

[ redirect to -hackers ]

I wrote:
>> Christophe Pettus <xof@thebuild.com> writes:
>>> A bit more poking revealed the reason: The ON HOLD cursor's query is executed 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 persist
>> 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

Attachments:

include-commit-processing-in-statement-timeout.patch (text/x-diff, 589B) download 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(); }

view thread (5+ messages)

Message-ID: <2899369.1632860114@sss.pgh.pa.us>
Permalink:  ../2899369.1632860114@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2899369.1632860114@sss.pgh.pa.us

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, xof@thebuild.com, pgsql-hackers@lists.postgresql.org
  Subject: Re: statement_timeout vs DECLARE CURSOR
  In-Reply-To: <2899369.1632860114@sss.pgh.pa.us>
  References: <A226617F-F248-4F92-BF62-5CF89EAAA148@thebuild.com> <B07C838E-5E08-40DC-89BD-BE6EB9EF8D80@thebuild.com> <2767393.1632771639@sss.pgh.pa.us> <2873020.1632859041@sss.pgh.pa.us> <2899369.1632860114@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox