pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Don't let libpq "event" procs break the state of PGresult object
Date: Fri, 18 Feb 2022 16:43:20 +0000
Message-ID: <E1nL6Lo-0006pN-O7@gemulon.postgresql.org> (raw)

Don't let libpq "event" procs break the state of PGresult objects.

As currently implemented, failure of a PGEVT_RESULTCREATE callback
causes the PGresult to be converted to an error result.  This is
intellectually inconsistent (shouldn't a failing callback likewise
prevent creation of the error result? what about side-effects on the
behavior seen by other event procs? why does PQfireResultCreateEvents
act differently from PQgetResult?), but more importantly it destroys
any promises we might wish to make about the behavior of libpq in
nontrivial operating modes, such as pipeline mode.  For example,
it's not possible to promise that PGRES_PIPELINE_SYNC results will
be returned if an event callback fails on those.  With this
definition, expecting applications to behave sanely in the face of
possibly-failing callbacks seems like a very big lift.

Hence, redefine the result of a callback failure as being simply
that that event procedure won't be called any more for this PGresult
(which was true already).  Event procedures can still signal failure
back to the application through out-of-band mechanisms, for example
via their passthrough arguments.

Similarly, don't let failure of a PGEVT_RESULTCOPY callback prevent
PQcopyResult from succeeding.  That definition allowed a misbehaving
event proc to break single-row mode (our sole internal use of
PQcopyResult), and it probably had equally deleterious effects for
outside uses.

Discussion: https://postgr.es/m/3185105.1644960083@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/ce1e7a2f716919652c280937087b24937677f8b3

Modified Files
--------------
doc/src/sgml/libpq.sgml             | 31 ++++++++++++++++---------------
src/interfaces/libpq/fe-exec.c      | 37 +++++++------------------------------
src/interfaces/libpq/libpq-events.c | 14 ++++++++------
3 files changed, 31 insertions(+), 51 deletions(-)



Message-ID: <E1nL6Lo-0006pN-O7@gemulon.postgresql.org>
Permalink:  ../E1nL6Lo-0006pN-O7@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1nL6Lo-0006pN-O7@gemulon.postgresql.org

 · 

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-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Don't let libpq "event" procs break the state of PGresult object
  In-Reply-To: <E1nL6Lo-0006pN-O7@gemulon.postgresql.org>
  References: <E1nL6Lo-0006pN-O7@gemulon.postgresql.org>

* 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