mirror of
https://github.com/postgres/postgres.git
synced 2025-10-29 22:49:41 +03:00
In libpq, don't look up all the hostnames at once.
Historically, we looked up the target hostname in connectDBStart, so that PQconnectPoll did not need to do DNS name resolution. The patches that added multiple-target-host support to libpq preserved this division of labor; but it's really nonsensical now, because it means that if any one of the target hosts fails to resolve in DNS, the connection fails. That negates the no-single-point-of-failure goal of the feature. Additionally, DNS lookups aren't exactly cheap, but the code did them all even if the first connection attempt succeeds. Hence, rearrange so that PQconnectPoll does the lookups, and only looks up a hostname when it's time to try that host. This does mean that PQconnectPoll could block on a DNS lookup --- but if you wanted to avoid that, you should be using hostaddr, as the documentation has always specified. It seems fairly unlikely that any applications would really care whether the lookup occurs inside PQconnectStart or PQconnectPoll. In addition to calling out that fact explicitly, do some other minor wordsmithing in the docs around the multiple-target-host feature. Since this seems like a bug in the multiple-target-host feature, backpatch to v10 where that was introduced. In the back branches, avoid moving any existing fields of struct pg_conn, just in case any third-party code is looking into that struct. Tom Lane, reviewed by Fabien Coelho Discussion: https://postgr.es/m/4913.1533827102@sss.pgh.pa.us
This commit is contained in:
@@ -312,7 +312,6 @@ typedef struct pg_conn_host
|
||||
char *password; /* password for this host, read from the
|
||||
* password file; NULL if not sought or not
|
||||
* found in password file. */
|
||||
struct addrinfo *addrlist; /* list of possible backend addresses */
|
||||
} pg_conn_host;
|
||||
|
||||
/*
|
||||
@@ -412,7 +411,9 @@ struct pg_conn
|
||||
/* Transient state needed while establishing connection */
|
||||
bool try_next_addr; /* time to advance to next address/host? */
|
||||
bool try_next_host; /* time to advance to next connhost[]? */
|
||||
struct addrinfo *addr_cur; /* backend address currently being tried */
|
||||
struct addrinfo *addrlist; /* list of addresses for current connhost */
|
||||
struct addrinfo *addr_cur; /* the one currently being tried */
|
||||
int addrlist_family; /* needed to know how to free addrlist */
|
||||
PGSetenvStatusType setenv_state; /* for 2.0 protocol only */
|
||||
const PQEnvironmentOption *next_eo;
|
||||
bool send_appname; /* okay to send application_name? */
|
||||
|
||||
Reference in New Issue
Block a user