Re: Infinite loop on error
Daniele Varrazzo <[email protected]> Thu, 5 Aug 2010 02:31:29 +0100
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
On Mon, Aug 2, 2010 at 7:56 AM, Marko Kreen <[email protected]> wrote: > On 8/2/10, Daniele Varrazzo <[email protected]> wrote: >> On Wed, Jul 28, 2010 at 4:54 PM, Marko Kreen <[email protected]> wrote: >> =A0> Psycopg has several loops in form: >> [...] >> =A0> The problem is that if libpq gets so fatal error it decides >> =A0> to close the connection, PQgetResult() will never return NULL >> =A0> from that connection, thus infinite loop. >> >> Are you sure about that? I don't have the libpq source code handy, I >> =A0will surely check that. > > Yeah, found out via strace/gdb... =A0strace was showing infinite > close(-1) - thus libpq was trying to close already closed connection. > >> But, if it doesn't return a NULL with the >> =A0connection in broken state... what does it return? > > Probably PQmakeEmptyPGresult(conn, PGRES_FATAL_ERROR) Yup, seen in the libpq source. >> =A0PQgetResult() also returns null when there is no result to fetch. I >> =A0may have extrapolated excessively assuming that it returns null when >> =A0the connection is closed too, but it doesn't seem an excessively >> =A0stretched interpretation. > > Yeah, seems NULL means "query is finished _and_ everything is fine". I shall propose a clarification to the pg docs ml. >> =A0I'm curious to do some test in the next days. > > Have fun. I did, but I've not been able to reproduce a loop (I've produced segfaults, crashes... but not an infinite loop). Do you have a recipe to reproduce it? I have a patch adding the proposed check to the loops (http://tinyurl.com/3463bql). If you can test it (or propose how to test it) it would be great. Thank you, cheers. -- Daniele