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: Restructure libpq's handling of send failures.
Date: Tue, 19 Mar 2019 20:20:40 +0000
Message-ID: <E1h6LE0-0001hK-7T@gemulon.postgresql.org> (raw)

Restructure libpq's handling of send failures.

Originally, if libpq got a failure (e.g., ECONNRESET) while trying to
send data to the server, it would just report that and wash its hands
of the matter.  It was soon found that that wasn't a very pleasant way
of coping with server-initiated disconnections, so we introduced a hack
(pqHandleSendFailure) in the code that sends queries to make it peek
ahead for server error reports before reporting the send failure.

It now emerges that related cases can occur during connection setup;
in particular, as of TLS 1.3 it's unsafe to assume that SSL connection
failures will be reported by SSL_connect rather than during our first
send attempt.  We could have fixed that in a hacky way by applying
pqHandleSendFailure after a startup packet send failure, but
(a) pqHandleSendFailure explicitly disclaims suitability for use in any
state except query startup, and (b) the problem still potentially exists
for other send attempts in libpq.

Instead, let's fix this in a more general fashion by eliminating
pqHandleSendFailure altogether, and instead arranging to postpone
all reports of send failures in libpq until after we've made an
attempt to read and process server messages.  The send failure won't
be reported at all if we find a server message or detect input EOF.

(Note: this removes one of the reasons why libpq typically overwrites,
rather than appending to, conn->errorMessage: pqHandleSendFailure needed
that behavior so that the send failure report would be replaced if we
got a server message or read failure report.  Eventually I'd like to get
rid of that overwrite behavior altogether, but today is not that day.
For the moment, pqSendSome is assuming that its callees will overwrite
not append to conn->errorMessage.)

Possibly this change should get back-patched someday; but it needs
testing first, so let's not consider that till after v12 beta.

Discussion: https://postgr.es/m/CAEepm=2n6Nv+5tFfe8YnkUm1fXgvxR0Mm1FoD+QKG-vLNGLyKg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/1f39a1c0641531e0462a4822f2dba904c5d4d699

Modified Files
--------------
src/interfaces/libpq/fe-connect.c   |  6 +++
src/interfaces/libpq/fe-exec.c      | 91 ++++++++++++++++++++++---------------
src/interfaces/libpq/fe-misc.c      | 53 +++++++++++++++++----
src/interfaces/libpq/fe-protocol2.c | 14 +-----
src/interfaces/libpq/fe-protocol3.c | 17 +------
src/interfaces/libpq/libpq-int.h    |  3 +-
6 files changed, 109 insertions(+), 75 deletions(-)



Message-ID: <E1h6LE0-0001hK-7T@gemulon.postgresql.org>
Permalink:  ../E1h6LE0-0001hK-7T@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1h6LE0-0001hK-7T@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: Restructure libpq's handling of send failures.
  In-Reply-To: <E1h6LE0-0001hK-7T@gemulon.postgresql.org>
  References: <E1h6LE0-0001hK-7T@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