> On 3. Dec 2021, at 18:14, Tom Lane <t...@sss.pgh.pa.us> wrote:
> 
> Daniel Frey <d.f...@gmx.de> writes:
>>> On 3. Dec 2021, at 17:00, Laurenz Albe <laurenz.a...@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't depend 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 
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?

Reply via email to