libpq should not look up all host addresses at once
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-hackers@lists.postgresql.org
Date: 2018-08-09T15:05:02Z
Lists: pgsql-hackers
Attachments
- libpq-delay-getaddrinfo-1.patch (text/x-diff) patch
Whilst fooling with the patch for CVE-2018-10915, I got annoyed by the fact that connectDBStart() does the DNS lookups for all supplied hostnames at once, and fails if any of them are bad. It was reasonable to do the lookup there when we only allowed one hostname, but now that "host" can be a list, this is really pretty stupid. The whole point of allowing multiple hostnames is redundancy and avoiding a single point of failure; but the way this is written, *each* of your servers' DNS servers is a single point of failure all by itself. If any one of them is down, you don't connect. Plus, in the normal case where you successfully connect to something before the very last host in the list, the extra DNS lookups are wasted --- and DNS lookups aren't that cheap, since they typically involve a network round trip. So I think what this code should do is (1) look up each hostname as it needs it, not all at once, and (2) proceed on to the next hostname if it gets a DNS lookup failure, not fail the whole connection attempt immediately. As attached. I'm tempted to call this a back-patchable bug fix, because the existing behavior basically negates the entire value of the multi-hostname feature once you consider the possibility of DNS server failures. But given the lack of field complaints, maybe that's an overreaction. I'll put this in the September fest for review. regards, tom lane
Commits
-
In libpq, don't look up all the hostnames at once.
- c781a066ea4f 11.0 landed
- 5ca00774194d 12.0 landed
- 6953daf08e6b 10.6 landed