Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 3DBB46336A8 for ; Fri, 6 Aug 2010 11:20:28 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 02244-03-2 for ; Fri, 6 Aug 2010 14:20:19 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 237FE633644 for ; Fri, 6 Aug 2010 11:20:21 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id o76EKIDj018522; Fri, 6 Aug 2010 10:20:19 -0400 (EDT) To: Daniele Varrazzo cc: pgsql-docs@postgresql.org, Marko Kreen Subject: Re: Documentation improvement for PQgetResult In-reply-to: References: Comments: In-reply-to Daniele Varrazzo message dated "Fri, 06 Aug 2010 14:53:38 +0100" Date: Fri, 06 Aug 2010 10:20:18 -0400 Message-ID: <18521.1281104418@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201008/8 X-Sequence-Number: 5832 Daniele Varrazzo writes: > documentation about the PQgetResult function suggests to "[call] > repeatedly until it returns a null pointer, indicating that the > command is done". This has lead psycopg developers to write code with > the pattern: > while (NULL != (res = PQgetResult(conn))) { > /* do something with res */ > PQclear(res); > } > Marko Kreen has pointed out > (http://lists.initd.org/pipermail/psycopg/2010-July/007149.html) that > this can lead to an infinite loop if the connection goes bad at the > rightly wrong time, advising then to check for the connection status > in the middle of the loop. libpq code seems actually returning > PQmakeEmptyPGresult(conn, PGRES_FATAL_ERROR) in case of something > unexpected. > If this is the case (I've not managed to reproduce it but the libpq > code seems clear), shouldn't the function documentation warn for this > risk, advising to check the connection status in the middle of the > loop and bail out if it's bad? No. I'm not convinced we need to do anything about that, since AFAIR no one has ever reported such a failure from the field (which might well indicate that Marko's analysis is wrong, anyway). But if we were to do something about it, changing the documentation would be the wrong response, because that coding pattern is all over the place. It'd be better to kluge PQgetResult so it only returns a bad-connection error object once per query, or something like that. regards, tom lane