pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Daniel Frey <d.frey@gmx.de>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: Re: libpq: Which functions may hang due to network issues?
Date: Sat, 04 Dec 2021 22:43:48 +0100
Message-ID: <36a1a59fcf09deec95b3abdec979d4d6b64a1a4a.camel@cybertec.at> (raw)
In-Reply-To: <B55956AC-ACB7-4827-9BFD-97F2A9AA606D@gmx.de>
References: <2B29B70E-2A78-49D3-9861-5DD289DC30DD@gmx.de>
	<d02a6212477706119f804b9206c32554c77e45fa.camel@cybertec.at>
	<0F84CF07-A88E-41A3-B41D-984EA6385AA2@gmx.de>
	<2311007.1638551661@sss.pgh.pa.us>
	<B55956AC-ACB7-4827-9BFD-97F2A9AA606D@gmx.de>

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






view thread (10+ messages)  latest in thread

Message-ID: <36a1a59fcf09deec95b3abdec979d4d6b64a1a4a.camel@cybertec.at>
Permalink:  ../36a1a59fcf09deec95b3abdec979d4d6b64a1a4a.camel@cybertec.at/
Also on:    postgresql.org/message-id/36a1a59fcf09deec95b3abdec979d4d6b64a1a4a.camel@cybertec.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: laurenz.albe@cybertec.at, d.frey@gmx.de, tgl@sss.pgh.pa.us
  Subject: Re: libpq: Which functions may hang due to network issues?
  In-Reply-To: <36a1a59fcf09deec95b3abdec979d4d6b64a1a4a.camel@cybertec.at>
  References: <2B29B70E-2A78-49D3-9861-5DD289DC30DD@gmx.de> <d02a6212477706119f804b9206c32554c77e45fa.camel@cybertec.at> <0F84CF07-A88E-41A3-B41D-984EA6385AA2@gmx.de> <2311007.1638551661@sss.pgh.pa.us> <B55956AC-ACB7-4827-9BFD-97F2A9AA606D@gmx.de> <36a1a59fcf09deec95b3abdec979d4d6b64a1a4a.camel@cybertec.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox