Search Postgresql Archives

Re: libpq: Which functions may hang due to network issues?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 2021-12-03 at 21:33 +0100, Daniel Frey wrote:
> 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 am tempted to say that you shouldn't use TCP with the requirement that it should not hang.

> 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?

You could start a separate process that has your PostgreSQL connection and kill it if it
times out.  But then you'd have a similar problem communicating with that process.

A normal thing to do when your database call times out or misbehaves in other ways is
to give up, report an error and die (after some retries perhaps).

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com






[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux