28 Jul 2010 17:54
Infinite loop on error
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.
I suspect only good fix is to check connection status in all places:
if (PQstatus(curs->conn) == CONNECTION_BAD) { }
Also as the construct is complex enough, it seems to call for a single
function...
--
--
marko
RSS Feed