Re: Infinite loop on error
Marko Kreen <[email protected]> Mon, 2 Aug 2010 09:56:09 +0300
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
On 8/2/10, Daniele Varrazzo <[email protected]> wrote: > On Wed, Jul 28, 2010 at 4:54 PM, Marko Kreen <[email protected]> wrote: > > Psycopg has several loops in form: > > > > while ((curs->pgres = PQgetResult()) != NULL) > > { > > } > > > > or > > > > do { > > pgres = PQgetResult(); > > } while (pgres != NULL); > > > > > > The problem is that if libpq gets so fatal error it decides > > to close the connection, PQgetResult() will never return NULL > > from that connection, thus infinite loop. > > > Are you sure about that? I don't have the libpq source code handy, I > will surely check that. Yeah, found out via strace/gdb... strace was showing infinite close(-1) - thus libpq was trying to close already closed connection. > But, if it doesn't return a NULL with the > connection in broken state... what does it return? Probably PQmakeEmptyPGresult(conn, PGRES_FATAL_ERROR) > PQgetResult() also returns null when there is no result to fetch. I > may have extrapolated excessively assuming that it returns null when > the connection is closed too, but it doesn't seem an excessively > stretched interpretation. Yeah, seems NULL means "query is finished _and_ everything is fine". > I'm curious to do some test in the next days. Have fun. -- marko