Re: BUG #5837: PQstatus() fails to report lost connection

From: "Murray S(dot) Kucherawy" <msk(at)cloudmark(dot)com>
To: Kevin Grittner <Kevin(dot)Grittner(at)wicourts(dot)gov>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #5837: PQstatus() fails to report lost connection
Date: 2011-01-24 18:04:14
Message-ID: F5833273385BB34F99288B3648C4F06F1341E73FCD@EXCH-C2.corp.cloudmark.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

> -----Original Message-----
> From: Kevin Grittner [mailto:Kevin(dot)Grittner(at)wicourts(dot)gov]
> Sent: Monday, January 24, 2011 9:50 AM
> To: Murray S. Kucherawy; Tom Lane
> Cc: Robert Haas; pgsql-bugs(at)postgresql(dot)org
> Subject: Re: [BUGS] BUG #5837: PQstatus() fails to report lost connection
>
> "Murray S. Kucherawy" <msk(at)cloudmark(dot)com> wrote:
>
> > Please, at a minimum, add some documentation about it.
>
> Current documentation at:
>
> http://www.postgresql.org/docs/9.0/interactive/libpq-async.html
>
> says:
>
> | PQgetResult must be called repeatedly until it returns a null
> | pointer, indicating that the command is done.
>
> What do you think would make this more clear?

"command is done" sounds like normal operation to me, but we're talking about an obvious exception here. The command (I assume that means the query that ultimately failed) can't even have started because the connection was gone. That's why I find the description misleading.

Indeed, the function order you're talking about is PQgetResult(), which returns non-NULL in this condition (which looks like there's a result available), but then PQresultStatus() returns PGRES_FATAL_ERROR. It's not very obvious to me that the right thing to do here is call PQgetResult() again just to get PQstatus() to tell me the truth. Now we're dealing with an exception rather than something normal.

So maybe something like this after the paragraph you cited would help:

"Note that after returning a PGresult object, PQresultStatus() could indicate a fatal error. The caller should still iterate calling PQgetResult() to completion (i.e. until it returns NULL) in order to allow libpq to process the error information completely."

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Murray S. Kucherawy 2011-01-24 18:14:43 Re: BUG #5837: PQstatus() fails to report lost connection
Previous Message Kevin Grittner 2011-01-24 17:49:52 Re: BUG #5837: PQstatus() fails to report lost connection