Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mtFF8-00004v-Fl for pgsql-general@arkaria.postgresql.org; Fri, 03 Dec 2021 20:33:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mtFF6-0006C0-Il for pgsql-general@arkaria.postgresql.org; Fri, 03 Dec 2021 20:33:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mtFF6-0006Br-6k for pgsql-general@lists.postgresql.org; Fri, 03 Dec 2021 20:33:16 +0000 Received: from mout.gmx.net ([212.227.15.18]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mtFF3-0004o0-Ht for pgsql-general@lists.postgresql.org; Fri, 03 Dec 2021 20:33:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1638563590; bh=0yTrYZYJ4PAWguFcICgDytHj2PnVYdIg5slutWxDpvA=; h=X-UI-Sender-Class:Subject:From:In-Reply-To:Date:Cc:References:To; b=MToAMDN1DeDNDcxMHablv09oWIY5pMAtN85T0MrTUYzbtGrCOGwHebF/7XpWpF/dw eKFuV1JIO2mXad4uf8QCkWDT663+wa82ohe4XFqL2yIXHSzkJNEnic7K4IejBAd3uz 46Irtq1oQy05+0uYyd7O0GnGq6r2rZ6vzcixemJM= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from smtpclient.apple ([79.249.154.197]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MysVs-1mfXue1LZC-00vt51; Fri, 03 Dec 2021 21:33:10 +0100 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 15.0 \(3693.20.0.1.32\)) Subject: Re: libpq: Which functions may hang due to network issues? From: Daniel Frey In-Reply-To: <2311007.1638551661@sss.pgh.pa.us> Date: Fri, 3 Dec 2021 21:33:09 +0100 Cc: Laurenz Albe , pgsql-general Content-Transfer-Encoding: quoted-printable Message-Id: References: <2B29B70E-2A78-49D3-9861-5DD289DC30DD@gmx.de> <0F84CF07-A88E-41A3-B41D-984EA6385AA2@gmx.de> <2311007.1638551661@sss.pgh.pa.us> To: Tom Lane X-Mailer: Apple Mail (2.3693.20.0.1.32) X-Provags-ID: V03:K1:wFhv9A+Dg4LVNBH4K1X3l9+QEgaGcp3prANvnECvt7O4qnnjlXp YO89iIMHhAHuzMBmmv3Cxog5TFIuXw8mmvEDaq/YF33nwYoJUBiFHxCppy9KD+1lhAC/vsP m2tl8AIiB4Kfe8Mu/AKFTCZlwnETQvG/TR9JQnVkwD5GgfAyYdPNBrQPjliXBZZOETHPdnw 90T89OyzD9627DQDgRuWA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:rZo8UXiou0o=:yViBIybhyxwNiOWj/OYntz LovSzHQmhCkCDDWLKxozsMPH/3bqYgapJ3PVERbGHzUUYz24OyeU/7CWpvPqZRiKmzwwJgfkA R1sR1nUAMcM6opbJGG7B45LEJMka5bDQ+xLdyaKIlpaMzgUwRlU9gdX0MAlnQk4r/GFy0KN5k TVcfpnzW5qvO5LVIQdvWeniGVXISdJpOaH4uxYB7SqNi/KyhJon78XerTCgBtlQJmUQG0sCJl temlxUdjl5ScI9ZcNPT7egoGRWrr5BUKB5twp0m08gZ0NAglGhxj6wJpwA1ztI1Sp7NIsxVJC em2KNhHs78+3nNjssvjdkokxDvVElPlfkrZ3533rsBOj8KCpiTlugDKQ8Ayjp1nO2suz//dAf 8hvTMVA4c6/i1aSp55UD9mgegW/gxeBsZZQnFnVtNUanJR+fAss7/fw5hPpnPtMDfiXFmPqF+ QJKO7ihGDE4yZX4ncLHlmpDGiV2IOsKfaS8oXGIfKSA8oTHvaDxs8dsg5jikBnoGUBJnwLKUI OlyutW8otAe9F6kqgqxNOg976x2K2wC6uxwkteOWyvzL2Mt4FdO51CZVx84Olov2EIfaw3EzD C4ZzIRy6tEKQyP/WZR4uzleHit8opEdPXk2oSPOgkTNsaJyoflmOFsYUxTyqY2Kf05piwuuEW kHhU0Yz68fdSRp4ztrpZV6UBaBedT0WN1e8kdnGXMmkRu5mnkz/aZXa46gss8xQws0WH1F0YI ZXLvn4m87026YKMvi6g+WRXzJxAJRbA3L7uTeZW3ckc6cZ3Pv/O7hXzSwslOuLMDDlIipJxku nLgt5kBFaDIn2CNohjL3h0y/HVkeBxYdynTOKAlLNqxXHYWWn4Nn2OTC3yXICdNnN6f+JgH6/ XMzNkinVxVO8u3hw9XNUcAgUoCS0F+IEB8L/zneLgElKBcgJCe+4oS6LQsZ9mMyrYZ25+QmA1 pjA+bcat8+a4MsCvahKF1uyhLFQvMFlmWTqolji5EQKKVfDlWTYBeypL9DRCWFtvw6/MzM5CU AqKcagMeGSx8uluP2AWZrcjJ5rLXk3sZaFAbSblSvbSP7cIKXYq+L+c273RFTb1l1zIn5iviF x4IOj4BJ0iGHWA= List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 3. Dec 2021, at 18:14, Tom Lane wrote: >=20 > Daniel Frey writes: >>> On 3. Dec 2021, at 17:00, Laurenz Albe = wrote: >>> On Fri, 2021-12-03 at 11:37 +0100, Daniel Frey wrote: >>>> Is there a complete list of methods that might wait for network = communication? >=20 >>> No; you have to read the code. >=20 >> I feel that this is insufficient, as the code might change. And it = might be simple enought for something like PQstatus(), but not all = functions are that simple. >=20 >> If this property of a function is not guaranteed by the = documentation, how am I expected to write a library that doesn't depend = on a specific version of libpq? Could these guarantees be added to the = documentation, please? >=20 > No. For one thing, we'd probably forget to maintain any such info. > In any case, I think you'd be best off to assume that anything that > isn't purely local state inspection might try to contact the server. > And it's not hard to see which ones are local state inspection. It might be "easy" for *some* functions to figure out that they won't = lead to any network communication, like PQstatus() or = PQtransactionStatus(). But expecting a user of libpq to inspect the = source code to figure that out and still have no guarantee for the = future seems extremely weird to me. If you put that guarantee in the = documentation and maybe add a comment into the source code, I don't see = how that would lead to anyone forgetting about it. But the real issue, at least for me, is PQfinish(). Considering that my = application is not allowed to hang (or crash, leak, ...), what should I = do in case of a timeout? I have existing connections and at some point = the network connections stop working (e.g. due to a firewall = issue/reboot), etc. If I don't want a resource leak, I *must* call = PQfinish(), correct? But I have no idea whether it might hang. If you = don't want to guarantee that PQfinish() will not hang, then please = advise how to use libpq properly in this situation. If there some = asynchronous version of PQfinish()? Or should I handle hanging = connections differently?=