Re: libpq: Which functions may hang due to network issues? - Mailing list pgsql-general

From Daniel Frey
Subject Re: libpq: Which functions may hang due to network issues?
Date
Msg-id B55956AC-ACB7-4827-9BFD-97F2A9AA606D@gmx.de
Whole thread Raw
In response to libpq: Which functions may hang due to network issues?  (Daniel Frey <d.frey@gmx.de>)
Responses Re: libpq: Which functions may hang due to network issues?  (Laurenz Albe <laurenz.albe@cybertec.at>)
List pgsql-general
> On 3. Dec 2021, at 18:14, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Daniel Frey <d.frey@gmx.de> writes:
>>> On 3. Dec 2021, at 17:00, Laurenz Albe <laurenz.albe@cybertec.at> 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?
>
>>> No; you have to read the code.
>
>> 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. 
>
>> If this property of a function is not guaranteed by the documentation, how am I expected to write a library that
doesn'tdepend on a specific version of libpq? Could these guarantees be added to the documentation, please? 
>
> 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
stillhave no guarantee for the future seems extremely weird to me. If you put that guarantee in the documentation and
maybeadd 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
stopworking (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
pleaseadvise how to use libpq properly in this situation. If there some asynchronous version of PQfinish()? Or should I
handlehanging connections differently? 


pgsql-general by date:

Previous
From: David Gauthier
Date:
Subject: Insert binary file into bytea where PG server does not have access to the file ?
Next
From: Adrian Klaver
Date:
Subject: Re: Insert binary file into bytea where PG server does not have access to the file ?