Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fnpkp-0008Cb-J2 for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Aug 2018 18:33:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fnpkn-0003Mp-Fn for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Aug 2018 18:33:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fnpkn-0003Mi-94 for pgsql-hackers@lists.postgresql.org; Thu, 09 Aug 2018 18:33:45 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fnpkk-0006ms-3B for pgsql-hackers@lists.postgresql.org; Thu, 09 Aug 2018 18:33:44 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w79IWwcv014648; Thu, 9 Aug 2018 14:32:58 -0400 From: Tom Lane To: Chapman Flack cc: pgsql-hackers@lists.postgresql.org Subject: Re: libpq should not look up all host addresses at once In-reply-to: <641169e3-0410-1317-c997-ceec24ff117a@anastigmatix.net> References: <4913.1533827102@sss.pgh.pa.us> <641169e3-0410-1317-c997-ceec24ff117a@anastigmatix.net> Comments: In-reply-to Chapman Flack message dated "Thu, 09 Aug 2018 14:18:36 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <14646.1533839578.1@sss.pgh.pa.us> Date: Thu, 09 Aug 2018 14:32:58 -0400 Message-ID: <14647.1533839578@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Chapman Flack writes: > On 08/09/2018 11:05 AM, Tom Lane wrote: >> 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. > Would it be worth the complexity to be a little async about it, > fling a few DNS requests out, and try the hosts in the order the > responses come back? It would be nice if an async connection request didn't have to block during DNS lookups ... but I don't know of any portable library API for async DNS requests, and it's most certainly not worth the trouble for us to write our own version of getaddrinfo(3). In practice, I think the async connection mode is mostly a legacy API at this point anyway; surely most people who need that sort of behavior are handling it nowadays by invoking libpq on a separate thread. So I just don't see it being worth a huge amount of work and maintenance effort to get that to happen. (Having said that, at least moving the lookup from connectDBStart into PQconnectPoll, as this patch does, is a step in the right direction.) Now that I think about it, there may be some text in the libpq docs claiming that the lookup happens in PQconnectStart not PQconnectPoll; that would need adjustment. regards, tom lane