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 1fojpd-0007mg-DO for pgsql-hackers@arkaria.postgresql.org; Sun, 12 Aug 2018 06:26:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fojpa-0006kv-7X for pgsql-hackers@arkaria.postgresql.org; Sun, 12 Aug 2018 06:26:26 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fojpZ-0006kn-Lb for pgsql-hackers@lists.postgresql.org; Sun, 12 Aug 2018 06:26:26 +0000 Received: from mail-pl0-x232.google.com ([2607:f8b0:400e:c01::232]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fojpV-0003oI-C5 for pgsql-hackers@lists.postgresql.org; Sun, 12 Aug 2018 06:26:24 +0000 Received: by mail-pl0-x232.google.com with SMTP id g6-v6so5643398plq.9 for ; Sat, 11 Aug 2018 23:26:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=bpz4X1hHMHFXgbZOzRKQthSyw9BfOVqBr4PwzHIrowo=; b=OVNQIw6LmSaHWhC986cTTQ5y5wme/JKAWcKvoTT6lbudTSXS4jChkfLd6eG7w8h0bK lkoobfWw4ekTGjnomeStUV1KUuU1BYomV1B52pXZBEdrmfedHoZZXFH/X/zUVTXeVaWR cBKpi7pM3BVWVB1RcwoUrgt7fLuY8zLUeP7qE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=bpz4X1hHMHFXgbZOzRKQthSyw9BfOVqBr4PwzHIrowo=; b=Y952BekMToPfMpXQ7hyxGjsDtBzEQK2Y5AfSLqsiGE41e6I0okyIDMdxBQ4sy+zuSA sW67zishYvr9WHlNYLCkcFNOpmO88IpTKi6zxrIfXFKpb5WR5skX11OhkcVOr4/de0LL 93zW6Ab12eW//ftDo+dLKBw0Cs+KGGL1+QGimOJwHJ+slHYJCk/EWBxHiD30RSuiCHs2 kBXBAC6sNw3ncFJRj8Y5PEUhYbj5abcFsqA2iOzE5YfQv+h3Cc5DHJehkT8ATvnb5aT2 JrzZ4kem8WfbScmPFE3Gef/eGP0nZEpA4PNUFpZhPnoUWy6V1OaxdCHm27CUvTwfoRbg LUTA== X-Gm-Message-State: AOUpUlHkDO51NCalMTQyhC6F14HkwiPIkgGI72xa1DyKRS2xZGFiFkYI 4UhQ2WzCVktwpCbRQi1+mSGXOv37Etk= X-Google-Smtp-Source: AA+uWPyQmoOHBwZmMv3aMgt16vhNA/t9nvuA7TAi/WLGaUvvaZCEknwxyzrY1uardL/6kr4c7ibK+Q== X-Received: by 2002:a17:902:820e:: with SMTP id x14-v6mr12068487pln.218.1534055179711; Sat, 11 Aug 2018 23:26:19 -0700 (PDT) Received: from rfd.leadboat.com (c-73-158-248-138.hsd1.ca.comcast.net. [73.158.248.138]) by smtp.gmail.com with ESMTPSA id d132-v6sm17508947pgc.93.2018.08.11.23.26.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 11 Aug 2018 23:26:18 -0700 (PDT) Date: Sun, 12 Aug 2018 06:26:15 +0000 From: Noah Misch To: Tom Lane Cc: Chapman Flack , pgsql-hackers@lists.postgresql.org Subject: Re: libpq should not look up all host addresses at once Message-ID: <20180812062615.GA2619236@rfd.leadboat.com> References: <4913.1533827102@sss.pgh.pa.us> <641169e3-0410-1317-c997-ceec24ff117a@anastigmatix.net> <14647.1533839578@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <14647.1533839578@sss.pgh.pa.us> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Aug 09, 2018 at 02:32:58PM -0400, Tom Lane wrote: > 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 https://c-ares.haxx.se/ is the async DNS API that I've experienced. It works well if you really need such a thing, but I haven't needed it in libpq.