Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 2A3721337B67 for ; Mon, 24 Jan 2011 14:14:54 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 76713-05 for ; Mon, 24 Jan 2011 18:14:46 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from ht1-outbound.cloudmark.com (ht1-outbound.cloudmark.com [72.5.239.35]) by mail.postgresql.org (Postfix) with ESMTP id 206CC1337B47 for ; Mon, 24 Jan 2011 14:14:46 -0400 (AST) Received: from EXCH-C2.corp.cloudmark.com ([172.22.1.74]) by malice.corp.cloudmark.com ([172.22.10.71]) with mapi; Mon, 24 Jan 2011 10:14:45 -0800 From: "Murray S. Kucherawy" To: Tom Lane CC: Robert Haas , "pgsql-bugs@postgresql.org" Date: Mon, 24 Jan 2011 10:14:43 -0800 Subject: Re: BUG #5837: PQstatus() fails to report lost connection Thread-Topic: [BUGS] BUG #5837: PQstatus() fails to report lost connection Thread-Index: Acu77fO/8YBvaNYCQqemOiA7HqIJLwAAA4rA Message-ID: References: <201101140136.p0E1aTFb017852@wwwmaster.postgresql.org> <1950.1295754244@sss.pgh.pa.us> <6493.1295882981@sss.pgh.pa.us> <9838.1295890896@sss.pgh.pa.us> In-Reply-To: <9838.1295890896@sss.pgh.pa.us> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.61 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201101/171 X-Sequence-Number: 29193 > -----Original Message----- > From: Tom Lane [mailto:tgl@sss.pgh.pa.us] > Sent: Monday, January 24, 2011 9:42 AM > To: Murray S. Kucherawy > Cc: Robert Haas; pgsql-bugs@postgresql.org > Subject: Re: [BUGS] BUG #5837: PQstatus() fails to report lost connection >=20 > >> This is complete nonsense. If you followed the documented method for > >> using PQgetResult -- ie, keep calling it till it returns NULL, rather > >> than assuming there will be a specific number of results --- then > >> PQstatus would show you the bad status afterwards. >=20 > > Your assertion here of "Read the result set to exhaustion, THEN check > > connection status to see if it was bad to begin with," can be politely > > described as counter-intuitive. >=20 > [ shrug... ] I guess if your intuition is that PQstatus should be > expected to intuit the failure of a call that hasn't happened yet, > then it's counter-intuitive. You're mixing internal implementation details with what the API consumer se= es. I don't expect PQstatus() to do anything other than tell me that a con= nection is no longer usable, which is what it's documented to do. I'm fine= with checking it after an error has been returned by some query-related fu= nction, which is what OpenDBX is doing. I don't know why that's "complete = nonsense". Look at the order of operations here: 0) A previous connection exists. The server is manually restarted. 1) A query is issued. This succeeds. 2) A request for results is issued. This returns non-NULL, apparently indi= cating at least one result object came back. 3) PQresultStatus() is called, and it returns PGRES_FATAL_ERROR. 4) PQstatus() is checked, and indicates no problem. 4a) A call to PQresultErrorMessage() indicates that the library knows the c= onnection was administratively reset. As a consumer of the API, not knowing (or wanting to know) what's going on = under-the-hood, this looks like a bug; the library certainly did know that = the connection can no longer be used or 4a wouldn't happen, but PQstatus() = is not saying so. The documentation I see at http://www.postgresql.org/doc= s/9.0/interactive/libpq-status.html doesn't lead me to believe that any of = this logic is faulty. That I have to iterate on step 2 above to get PQstat= us() to eventually tell me the truth even though I know something has gone = wrong already seems strange, and that's why I raised this issue. Another possible explanation is that PQresultStatus() doesn't give a consis= tent result until after PQgetResult() has returned NULL. If that's the cas= e, it should be documented, because right now it isn't. -MSK