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: Fix libpq's implementation of per-host connection timeouts.
Date: Mon, 13 Aug 2018 17:08:06 +0000
Message-ID: <E1fpGK6-00079T-QW@gemulon.postgresql.org> (raw)

Fix libpq's implementation of per-host connection timeouts.

Commit 5f374fe7a attempted to turn the connect_timeout from an overall
maximum time limit into a per-host limit, but it didn't do a great job of
that.  The timer would only get restarted if we actually detected timeout
within connectDBComplete(), not if we changed our attention to a new host
for some other reason.  In that case the old timeout continued to run,
possibly causing a premature timeout failure for the new host.

Fix that, and also tweak the logic so that if we do get a timeout,
we advance to the next available IP address, not to the next host name.
There doesn't seem to be a good reason to assume that all the IP
addresses supplied for a given host name will necessarily fail the
same way as the current one.  Moreover, this conforms better to the
admittedly-vague documentation statement that the timeout is "per
connection attempt".  I changed that to "per host name or IP address"
to be clearer.  (Note that reconnections to the same server, such as for
switching protocol version or SSL status, don't get their own separate
timeout; that was true before and remains so.)

Also clarify documentation about the interpretation of connect_timeout
values less than 2.

This seems like a bug, so back-patch to v10 where this logic came in.

Tom Lane, reviewed by Fabien Coelho

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

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/998c7366414ad6f93c2643339499ce9e6ab007eb

Modified Files
--------------
doc/src/sgml/libpq.sgml           |  9 +++++----
src/interfaces/libpq/fe-connect.c | 35 ++++++++++++++++++++++-------------
2 files changed, 27 insertions(+), 17 deletions(-)



view thread (3+ messages)

Message-ID: <E1fpGK6-00079T-QW@gemulon.postgresql.org>
Permalink:  ../E1fpGK6-00079T-QW@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1fpGK6-00079T-QW@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: Fix libpq's implementation of per-host connection timeouts.
  In-Reply-To: <E1fpGK6-00079T-QW@gemulon.postgresql.org>
  References: <E1fpGK6-00079T-QW@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