From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
Subject: | pgsql: Restructure libpq's handling of send failures. |
Date: | 2019-03-19 20:20:40 |
Message-ID: | E1h6LE0-0001hK-7T@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers |
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(-)
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2019-03-19 20:58:27 | pgsql: Hack back-branch SSL tests to avoid intermittent buildfarm failu |
Previous Message | Alexander Korotkov | 2019-03-19 18:01:57 | pgsql: Rename typedef in jsonpath_gram.y from "string" to "JsonPathStri |